查看: 3415|回复: 0

[二次开发源码] UG NX二次开发源码分享:有关用户设置方面的使用

[复制链接]

4

主题

3

回帖

46

积分

管理员

积分
46
发表于 2014-3-13 11:22:36 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×
有关用户设置的使用,如果你想设置一个模版文件,可以通过下列方式:% ], d3 X2 q* n: o1 y5 _

) ]6 r& V* y& }
  1. ) u! w4 |- A( r1 d, W' M2 H
  2. #include <uf_defs.h>* O7 q  I& k# B1 e  q7 c1 M9 C6 }
  3. #include <NXOpen/NXException.hxx># ?% [" R& h8 Q% y
  4. #include <NXOpen/Session.hxx>
    6 j9 g+ m4 A6 ~9 \
  5. #include <NXOpen/Builder.hxx>
    * m! i3 s$ \" A+ B8 x
  6. #include <NXOpen/FileNew.hxx>8 \- h1 t& m, v' p
  7. #include <NXOpen/NXObject.hxx>
    ! n% \1 p  N& f, r8 t0 O2 c
  8. #include <NXOpen/Part.hxx>
    2 J7 R, ^: F" y0 s' w( z' c" \
  9. #include <NXOpen/ParTCollection.hxx>
    1 _# m; M7 i5 v
  10. #include <NXOpen/Preferences_PartPreferences.hxx>
    & H8 `4 Z7 |% R' U8 b
  11. #include <NXOpen/Preferences_PartSketch.hxx>& X) V. G. A9 o
  12. #include <NXOpen/Preferences_SessionPreferences.hxx>7 n+ q! Y8 C0 D9 ?8 e
  13. #include <NXOpen/Preferences_SessionSketch.hxx>
    6 n9 ~8 H1 T3 e# K' y1 i9 ]
  14. #include <NXOpen/Preferences_WorkPlane.hxx>- K7 ~8 M2 z' U% P/ o
  15. #include <NXOpen/Session.hxx>+ ~. C  J1 s+ s, J- D
  16. using namespace NXOpen;( F# y1 l0 k; w( A1 S, ?8 c
  17. - j7 V" p  B7 S
  18. extern "C" DllExport int ufusr_ask_unload()+ y9 E. D/ V1 z* g* B: z* y
  19. {
    6 z0 u! j! t" U1 i. \3 j* T/ K/ y
  20.     return (int)Session::LibraryUnloadOptionImmediately;! m" Q2 c- d0 u$ H, ]0 t$ f, v
  21. }; H+ J1 r6 n3 f1 j/ U! j' `
  22. 9 _4 b# h  \" h: G" G; u" K/ a
  23. extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
    7 l* u$ V9 j6 v5 n2 x: o
  24. {
    8 f8 x, T# V& J0 E& Q
  25.     Session *theSession = Session::GetSession();9 h* `% P9 ?& [# c  u
  26. ( y0 k8 s6 s. D( C0 r
  27.     //Creates New Part with name as Preferences.prt, S" \* \; J) Q$ G8 Z* e, s+ |7 j
  28.     NXOpen::Part *part1;
    , A1 H" Z2 }1 R( I* j. n+ ]% N' o
  29.     part1=theSession->Parts()->NewDisplay("Preferences",Part::UnitsMillimeters);
    6 B5 A. D% g, r  t3 _
  30.     Part *workPart(theSession->Parts()->Work());
    6 m7 |: d3 C* ?5 C" O
  31.     Part *displayPart(theSession->Parts()->Display());
    5 E' t  Q4 [* h* b9 A/ }

  32. & b2 k6 ~1 k) N4 y! Y

  33. ' l6 t, U& M' o3 @
  34. " K* P  P  v4 o! Y. o
  35.     // ----------------------------------------------
    " Q& O4 c5 i; N" h' @* m. w2 k
  36.     //  Changing Sketch Prefix names5 s0 F' o, J8 _
  37.     // ----------------------------------------------   
    $ X8 X3 B! }1 E( W+ I# I" T& m
  38.       " P2 A+ _8 l9 C  E+ e( U
  39.     theSession->Preferences()->Sketch()->SetDefaultSketchNamePrefix("SKT_");
    . N4 K/ M7 U) h) [" C8 R) V- t

  40. - H* H. Z  A. O
  41.     theSession->Preferences()->Sketch()->SetDefaultVertexNamePrefix("VRT_");$ o, h3 e$ j# M! c( |
  42. * T+ k6 ^+ S" B9 b' ]( l, z/ y
  43.     theSession->Preferences()->Sketch()->SetDefaultLineNamePrefix("LIN_");1 d( J2 u8 ]# m$ M- w' m
  44. + g5 L2 g$ T1 H) l/ t* Q4 k
  45.     theSession->Preferences()->Sketch()->SetDefaultArcNamePrefix("ARC_");
    * [% U# b2 M2 M) D$ [# n/ {, J; C: E! v
  46. ( N. d. J8 \- S, i  l- Y- _! b
  47.     theSession->Preferences()->Sketch()->SetDefaultConicNamePrefix("CON_");
    + S5 u; X! S" T  C1 E* q5 g; K2 N

  48. ' x! a9 j/ }4 _9 J% S- D
  49.     theSession->Preferences()->Sketch()->SetDefaultSplineNamePrefix("SPL_");      
    9 V% I+ \$ [7 f' [! A" c& y
  50.    : q5 d6 x# O. Q3 o- w5 C
  51.     9 U5 V! H1 Z- H4 G
  52.     // ----------------------------------------------
    7 i5 l- W" e- U
  53.     //  Changing Grid values
    8 w& o. N* ?$ z
  54.     // ----------------------------------------------  
    . N( E3 o+ J, Z: O' v
  55.     ; f! i8 g2 {9 L$ V: A# }  ^: \2 u
  56.     Preferences::WorkPlane *workPlane1;
    / K/ [3 s6 d; ~: ~# o
  57.     workPlane1 = workPart->Preferences()->Workplane();- d) J5 C8 o8 Y4 [9 }+ N9 d5 K3 A$ }
  58.    
    - N( N+ N4 Z4 I3 x3 |4 c* K, w
  59.     workPlane1->SetGridType(Preferences::WorkPlane::GridPolar);
    & t* g) p  C! h1 y
  60.    
    0 K- q1 }- I# U: I; s+ H+ c
  61.     Preferences::WorkPlane::PolarGridSize polarGridSize1;, r& g. A$ {" P) }- C1 h
  62.     polarGridSize1.RadialGridSize.MajorGridSpacing = 75.0;" H5 V# p# |7 [; l
  63.     polarGridSize1.RadialGridSize.MinorLinesPerMajor = 3;
    1 B3 \& a  M4 O. E. \
  64.     polarGridSize1.RadialGridSize.SnapPointsPerMinor = 5;
    9 q! t/ J$ H- D" N3 r
  65.     polarGridSize1.AngularGridSize.MajorGridSpacing = 45.0;( |+ y& d; K- y* x# U  H3 M6 C! o; I+ G
  66.     polarGridSize1.AngularGridSize.MinorLinesPerMajor = 4;: _( G! D- M. q  [0 l1 ~3 Y
  67.     polarGridSize1.AngularGridSize.SnapPointsPerMinor = 2;* V- [/ r# A+ o" N( I& G  p
  68.     workPlane1->SetPolarGridSize(polarGridSize1);  a% h9 H7 M) z& m
  69.     2 d7 v" O2 U5 h8 w, L' C. @5 p
  70.     workPlane1->SetShowGrid(true);! u# @1 T/ S- e8 f3 w5 c
  71.    
    ' m, G' x! G0 K" \
  72.     workPlane1->SetShowLabels(false);
    & r6 t& q8 [" X: o
  73.     - q: A& h3 f1 d
  74.     workPlane1->SetSnapToGrid(false);& V" \1 q$ n( U" z+ h1 ~. c# q0 M
  75.     + l) I6 k4 V# ?5 l3 K
  76.     workPlane1->SetGridOnTop(false);: Y% m% y6 D  u
  77.     7 G. D% _3 Y! x
  78.     workPlane1->SetRectangularShowMajorLines(false);  K0 H  i8 |- x" n" `3 S
  79.    
    2 [$ [2 M  b& ]  f
  80.     workPlane1->SetPolarShowMajorLines(true);. k  N5 r8 l* D# Y
  81.    
    1 T$ j2 o' B( @( h& }: g
  82.     workPlane1->SetGridColor(130);# J1 J/ z. V+ a
  83. }
复制代码
' n% }6 D! m) `
! D% u$ t* J1 w7 z

, s8 V* Q' ]. g- P+ f& b
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部