青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

青华模具培训学院
查看: 1959|回复: 19

[疑难] UG二次开发获取零件的密度和质量信息

[复制链接]
发表于 2015-4-18 09:41 | 显示全部楼层 |阅读模式
想用二次开发的方法获取零件的密度,质量体积形心信息
3 o& V* w- P) X$ I+ D4 M
发表于 2015-4-18 11:50 | 显示全部楼层
UF_MODL_ask_mass_props_3d
回复 支持 反对

使用道具 举报

发表于 2015-4-18 11:50 | 显示全部楼层
UF_MODL_ask_body_density
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-21 15:50 | 显示全部楼层
        double *masscenter=new double[3];0 f0 E8 q0 r0 e6 Y  i
        double*acc_value=new double[11];) t' Y+ Z* e2 }! X, D8 P
        double*mass_props=new double[47];
# Q2 P) I) w3 d- o) O& {        double*statistics=new double[13];; @4 m4 r4 L7 @( {0 _
        UF_MODL_ask_mass_props_3d(&partTag,1,1,3,1,2,acc_value,mass_props,statistics);
+ r5 S: b& K6 N1 {# a% a9 {- B3 m        masscenter[0]=mass_props[3];- B" \+ D, V+ X  @
        masscenter[1]=mass_props[4];% x$ g: g& V1 d7 p! \2 P0 Z; ~' J) I
        masscenter[2]=mass_props[5];
5 D+ X* z8 M. Z  U' C2 Y. m我这样写得到的是. D5 w! ^) l$ H: {1 z0 |3 u5 a
质心x=-6.27744e+066
# H: F) }4 z5 n6 A' k质心y=-6.27744e+066
) t& u1 I0 l& N: m质心z=-6.27744e+066$ s% g: C: h) M8 C9 U, N
是不是那块有错啊@victor_tech

点评

masscenter这些不用动态内存,直接数组就行了!  详情 回复 发表于 2015-4-22 19:14
回复 支持 反对

使用道具 举报

发表于 2015-4-21 19:13 | 显示全部楼层
本帖最后由 ypcopy 于 2015-4-21 19:15 编辑 ) l! X; Y# f9 Y/ C; T. n
3 e5 H" A% ]5 r; n* K2 B9 J
void masscenter()
7 [* K# h% h8 I# P1 M. @: m{
6 d1 m: v0 \& v/ N- z        tag_t workpart=UF_PART_ask_display_part        (        );
. q$ E$ y- s9 k7 B3 k7 h3 V! O% g        7 z: s0 x- \2 I, |
        UF_WEIGHT_properties_s properties;: U- B) u0 z8 J0 n9 L9 ~2 h. s
                UF_WEIGHT_exceptions_t exceptions ;
! E: `* j0 j5 r
' k. Q3 W( T& S+ s9 U+ ~" z                UF_WEIGHT_init_exceptions(& exceptions );
% Q2 M7 W) b/ C+ O' w8 R                UF_WEIGHT_estab_part_props(+ F( O; U# v. S3 G( b
                workpart,
8 |7 Y. X0 f# x' ~$ {                0.999,
* V, i0 f# h) y: D                true ,                UF_WEIGHT_units_gm,
- V+ s8 g+ o* c: f1 q, D) j9 `% I' \& K
                & properties,
' d4 j% }. ]3 Q9 C7 a. a9 P                &exceptions
; t4 Q# A4 z# L. {/ N                );; L$ B% X) M1 m: j2 i# c
        double masscenter[3]={/ O; }: y" Z4 }/ m$ g
                properties.center_of_mass[0],
" ~7 }' b- V8 I6 e$ y                properties.center_of_mass[1],
5 K  P2 a3 r5 P8 ?( t4 d# l                properties.center_of_mass[2]
* H, R, Z' n% Z( Q' [        };' v' w( @! I3 O( f# d& l
        Session::GetSession()->ListingWindow()->Open();9 d. P( B- W/ W8 u1 i5 L. a+ A+ A
        char tt[132];' R7 g: j0 ]2 p2 q( f
        sprintf(tt, "x:%f\ny:%f\nz:%f\n ",
. e3 Y4 {8 f3 d7 Z$ o9 y6 D                masscenter[0], masscenter[1], masscenter[2]);
! P, Q: a! T4 z, _        Session::GetSession()->ListingWindow()->WriteLine(tt);* i& Z+ B* `! j, F8 Z" e. ^

' J" s. J) b$ T' F' V7 w8 G}

NX8_Open2.rar

8.36 KB, 下载次数: 16, 下载积分: G币 -1

售价: 3 G币  [记录]

评分

参与人数 1流量 +2 技术 +1 激情 +6 G币 +10 收起 理由
victor_tech + 2 + 1 + 6 + 10 赞一个!

查看全部评分

回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-22 17:13 | 显示全部楼层
ypcopy 发表于 2015-4-21 19:131 L- R6 g" P; H# `- h
void masscenter()
" C9 d9 O6 O3 e& }0 Z7 H  u' p# r( j0 n{  q7 X) [" m# ?; ]9 X% O
        tag_t workpart=UF_PART_ask_display_part        (        );
9 a: F5 `. I! j
大师,能把生成DLL文件的整个程序代码发一下吗?
回复 支持 反对

使用道具 举报

发表于 2015-4-22 19:14 | 显示全部楼层
西尔贝 发表于 2015-4-21 15:50# `0 S! Q( G; v
double *masscenter=new double[3];
. r, c( ~; B& z        double*acc_value=new double[11];
9 z/ ]& F1 T+ U9 A% a9 J/ @        double*mass_props=new double ...

7 U, S! b. J1 @& I1 [. jmasscenter这些不用动态内存,直接数组就行了!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-23 21:19 | 显示全部楼层
victor_tech 发表于 2015-4-22 19:14
5 p1 [" ?) w) x! xmasscenter这些不用动态内存,直接数组就行了!
2 s" B7 n9 J: S
用数组了,还是不行啊,,,着急
9 O9 P( p8 T! a. c) A  S* ^5 i& ~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-23 21:31 | 显示全部楼层
这是我的全代码,那块是不是有错,怎么一直得不到实体的重心位置和密度值呢
4 o0 J4 U, j0 _7 m7 ]+ F#include "afx.h"
; Q1 @/ p8 Z$ w" m% E: o4 U#include <iostream>
2 l6 S; _+ b/ u9 S) L( r6 ]#include <uf.h>
! ]; P  T: ^  H% U+ m+ b: P#include "uf_part.h"& z/ ?3 j' \' [! G# J6 d
#include <uf_attr.h>$ t0 a% J; t' i2 D# l( d2 x; T  V
#include <uf_ui.h>3 v. z& N: V/ M$ @$ W6 w
#include <uf_obj.h>4 V5 z, w. @& h; \( T
#include "uf_modl.h"6 E/ S) G+ h5 r
#include "uf_weight.h"& o# |" y* z( }  t' n6 d
#include "uf_modl_types.h "- }% }* z( A5 {) g4 f% S
#include "stdafx.h"$ H( ~" X, S& G

+ Z2 `& Q4 f# C# S5 K7 S' |! j) cusing namespace std;
" r' T2 i3 ^* {( R" a3 c- ?+ I$ o  e- t
int main()
" ]5 q& Z& b7 O' J% r! J' Q{8 A! _/ m  o0 [6 I& x5 Y. }1 j4 D/ A
        int                    nRetCode = 0;8 l9 ?9 T+ I! \  F. e, w5 N/ G: k
        int                    rcode;
8 Q! C9 g, E4 Y+ r; p4 u    CString                partName = "e:\\a.prt";  //此处为创建block的全路径名
7 P$ T' G& o1 t, I( c7 q5 C        tag_t                  partTag = NULL_TAG;
7 k) X$ g5 T* s5 M        tag_t                  attrTag = NULL_TAG;
2 P( z. Y# a, P8 r! ~        tag_t                  obj1 = NULL_TAG;
9 J9 s. ~. l: ]9 \3 z+ w/ l        UF_PART_load_status_t  error_status;! ~3 Z; ]6 `! j4 T
) c4 n8 ]& D& @8 H# R6 J, J! a
        // initialize UG and print and error on failure
% E0 g& k- A3 b" c( O' _        rcode = UF_initialize();
5 U4 U8 n! B9 C! J# \6 ?# d9 N$ ?- W( D3 _) _+ m  T
        if ( rcode )% C0 \& l* u4 X! `/ d
        {2 I/ r! r1 e/ L3 K+ P- t9 R
                // TODO: change error code to suit your needs
! ]: s3 T" o* S. \$ ^                cerr << _T("Fatal Error: UG initialization failed") << endl;
: J* K! Y& ~2 A) X                nRetCode = 1;7 q8 ]1 R/ V7 g: ~8 d" ~
        }
, A" i7 T; x% u+ s: k        else" w) P; _, O6 Y6 J/ C3 W% k
        {
0 V+ i3 z0 F5 m                // TODO: code your application's behavior here.
: K" R- @# n9 h9 x" K        //把部件载入内存
0 |. P1 K3 ~2 \& K                UF_PART_open_quiet((char *)(LPCTSTR)  partName,
0 A% {+ v. `. x  s! }3 N                                             &partTag,
$ l2 g+ V8 w; J                                             &error_status);  
$ Z' W6 ^' `6 Y! o
1 O$ {0 Y2 x% u" p7 U) F                //得到对象标识
- `+ j" K( g7 H/ ]$ G" |# o2 {        UF_OBJ_cycle_objs_in_part( partTag, UF_feature_type, &obj1 ); 1 ]; l* \" A& A# p- q0 h/ q

) s9 L% o- W3 K# X6 b/ k                //使用这个函数把部件做为工作部件
5 p- z% r( C9 w0 j6 y8 o8 I  [  UF_PART_set_display_part(partTag);
" q  U* L5 u2 i+ K5 b                int i;
! P; Z* d$ `6 n; t" ^                char *size[3];
+ ?! W9 ?$ H9 V; A                UF_UI_open_listing_window();' [5 I2 d$ F) T3 I
                UF_MODL_ask_block_parms(obj1,1,size);4 b% \( U# `4 g
: N/ W0 D1 ]8 _3 r3 I
                for(i=0;i<3;i++)
/ O, j* z3 B; X$ j2 v1 y                {
, I+ x# r1 j0 A4 z0 r                        UF_UI_write_listing_window(size[i]);* \9 u; j9 X- b( s6 p( B, _
            UF_UI_write_listing_window("\n");
+ k2 E' ~6 A# z' A; b) u; [                }: A: l& f. T5 |; i" z
        tag_t bodies[1];% U+ j5 ?, k( R% I+ Q) ?4 M0 x2 [
        bodies[0]=partTag;  A' B* m9 ^0 [: _" @$ v- d# L. w
        double acc_value[11];! p5 L! l2 Q3 k9 ?" S$ i
        double mass_props[47];7 L& U' |1 w! I1 Z" J
        double statistics[13];8 ^2 o: y$ ^' ?2 M9 J& j7 Y
        UF_MODL_ask_mass_props_3d(bodies,1,1,3,1,1,acc_value,mass_props,statistics);
# T! |: ~. b0 j) ?* z1 v/ @. G                double masscenter[3]={
: A( p) {- ~: g0 u! f                mass_props[3]*10,
& v; C: a) l  P( X% {) p                mass_props[4]*10,
" G* h+ d' W. q                mass_props[5]*10};3 y6 H3 s+ C! v: Y/ t, o: C
    cout << "质心x="<<masscenter[0]<< endl;
  R5 U) s; C( f( C4 Q( }8 ^& c3 z: E        cout << "质心y="<<mass_props[4]<< endl;: r% \) S$ H2 j) y6 I. |! F
        cout << "质心z="<<mass_props[5]<< endl;
$ j6 A# M( ~* P- p, j- v7 m; x        cout << "密度="<<mass_props[46]<< endl;8 u1 r+ E4 R, E/ [0 ~. _
          4 l! E0 l" w& a
    UF_terminate();
0 _9 |" w9 K6 d8 S3 H        }0 B* T* n# }# N3 q2 q& K
) W; ?! i  I0 P& e2 Y# o: d
        return nRetCode;$ s# H! }3 m  \8 ^) `+ t
}
6 J6 U. P& f+ ^$ _, x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-23 21:37 | 显示全部楼层
victor_tech 发表于 2015-4-18 11:508 H; z$ i/ Y- k  _% Y  Y9 p
UF_MODL_ask_mass_props_3d

  t0 ?2 v: x6 z' K! O3 N帮我看看把那块错了
2 C8 L/ T0 V' s7 p2 Z#include "afx.h"1 T! W. u) n" X$ g
#include <iostream>
9 D- i+ M+ {: ?; ^& ~& n7 I#include <uf.h>* }7 a3 ]7 @" T' S1 z! N( x& M
#include "uf_part.h". m- @+ Q3 X  y
#include <uf_attr.h>' }+ P* E3 B, [$ p
#include <uf_ui.h>
3 T/ B3 H9 r0 a6 I& p#include <uf_obj.h>6 ]! ]0 f( l9 s5 b: Y, ~6 U
#include "uf_modl.h"
6 ], N; L6 n( R; Q1 v1 ~#include "uf_weight.h"
* h7 C; B2 e& J' {) f# s, A#include "uf_modl_types.h "2 r& C) e; P. J
#include "stdafx.h"
# Z/ K% H: Y1 G, o. t0 T: R% f& ]: D; [' |2 a. u' h0 ^
using namespace std;
1 ?% K7 A# Q2 E/ n/ f0 F# M) H* J, a5 t' J, |" `- B
int main()
- E, y3 i# @$ K- K{$ H% u  j! F* ^$ \' S
        int                    nRetCode = 0;
) l. q( d% e; f7 W! W  N9 B        int                    rcode;1 r; l2 E) z  z6 C6 c
    CString                partName = "e:\\a.prt";  //此处为创建block的全路径名
: g; [) [) I0 `7 r' ^- p! C        tag_t                  partTag = NULL_TAG;8 G% o- e, b& `- V5 P
        tag_t                  attrTag = NULL_TAG;: U2 J' x# a% C5 F$ h
        tag_t                  obj1 = NULL_TAG;
8 |+ o: S$ ~  X% z" m        UF_PART_load_status_t  error_status;
- j% v% B+ v5 W4 u9 \1 W7 ~
7 L. n1 ~# z0 x- |5 w5 D        // initialize UG and print and error on failure' I" r4 a+ o6 S
        rcode = UF_initialize();" z4 U0 K( z- J! @9 i. ]
  D0 g4 r# ?* K) ]1 f& g
        if ( rcode )
0 y1 ]: c) C7 \! u        {
" ^. W! W' D7 ^6 O8 Y- f, S                // TODO: change error code to suit your needs$ B7 Z& d' q$ P
                cerr << _T("Fatal Error: UG initialization failed") << endl;
$ z- U' V- M# }( U8 P4 j                nRetCode = 1;
' Y1 K/ I! ~: }3 H% Q  d* x2 t        }
% m* p& f2 C0 K/ [& w3 x5 \+ T        else. I+ L, K7 o+ e% Y3 D2 v
        {
8 O1 I8 g9 a0 x, G( \8 y                // TODO: code your application's behavior here.
2 ^! C, I  ^, A; x$ L        //把部件载入内存
1 I' c& f- r# p7 a2 r2 b                UF_PART_open_quiet((char *)(LPCTSTR)  partName,
; g% A$ q" R5 u3 @0 A2 S! v                                             &partTag, 6 C: n# b4 V9 d6 i- d" {
                                             &error_status);  
9 B' V! v2 ~% R  t- O& T6 }. E  J- t1 S
                //得到对象标识$ U  R$ v  V9 z& D
        UF_OBJ_cycle_objs_in_part( partTag, UF_feature_type, &obj1 );
- u1 q1 A/ v2 w/ Q) ?% i4 ?. Q( H' R% S; w
                //使用这个函数把部件做为工作部件
2 G, q$ i8 a, X1 A: p  UF_PART_set_display_part(partTag);
2 @% b6 O. L: s- A6 a, V+ \' h8 ^                int i;
; g2 {. Y& g! j4 C) E$ h                char *size[3];. F' p/ t: D6 y! ~) O
                UF_UI_open_listing_window();
0 X+ t1 i. @1 K: I9 Z8 i) M7 Z( m                UF_MODL_ask_block_parms(obj1,1,size);
; e2 e& U3 s" S) @0 h8 N
( [7 t, n' W2 G4 ^7 Z8 `  t0 z5 o8 Z                for(i=0;i<3;i++); t. P) V" Q7 [' \  F
                {3 C% z, m4 T: ?" K# z7 s
                        UF_UI_write_listing_window(size);9 p* c1 w7 l( J& [& G; c
            UF_UI_write_listing_window("\n");9 i- V- S7 i- @9 }( v
                }
( N2 Z1 L/ S8 J+ |: l        tag_t bodies[1];
, r  x( y1 A# h" _; n- B5 `        bodies[0]=partTag;( ~. B4 A; D/ o0 O( m
        double acc_value[11];
  i0 Z# y  O4 D! y9 ~        double mass_props[47];
4 O6 b3 p7 Y& R' ]1 d- ]1 `7 s        double statistics[13];
. p5 R9 h- h  ^. v; o, E; H        UF_MODL_ask_mass_props_3d(bodies,1,1,3,1,2,acc_value,mass_props,statistics);
7 }* k3 b1 [* `) m$ D        double masscenter[3]={
; h2 k% u' p3 {                mass_props[3]*10,
0 H/ h) h6 C- R! E4 i                mass_props[4]*10,! k5 Y& R' ?' K' c0 p
                mass_props[5]*10};
1 d! V  t' P4 B/ F  v    cout << "质心x="<<masscenter[0]<< endl;5 D: l( s# I' ]  O3 ^0 o
        cout << "质心y="<<mass_props[4]<< endl;+ a" x1 D9 o  o& M( S
        cout << "质心z="<<mass_props[5]<< endl;
5 I4 I5 ?& Y3 e' W3 ^7 {' D        cout << "密度="<<mass_props[46]<< endl;" c7 u! h! |: J8 w3 I
          2 D: r  M2 W% P% |
    UF_terminate();0 [5 D4 Z2 q5 ]. s  q
        }
" J* P; Y+ ]3 N% G
, Q6 I% n4 c% l        return nRetCode;
& N  j# a* {+ Q}
% Z* Q! x# N! R- X# n
: t; p, ]/ F) Y- i3 ^+ E; z# G5 U* l$ v& p. _% g
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|关于我们|sitemap|小黑屋|Archiver|手机版|UG网-UG技术论坛-青华数控模具培训学校 ( 粤ICP备15108561号 )

GMT+8, 2025-6-28 08:21 , Processed in 0.068799 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表