乙個python的UG二次開發簡單例項

2021-10-13 21:22:54 字數 2684 閱讀 2149

今天好像搞明白了,ecilpse的python開發環境如何使用的問題。基本步驟如下

1)開啟ecilpse和ugnx

2)啟動ecilpse的除錯服務(debug server)並開啟需要測試的指令碼

3)在ugnx中執行指令碼回放功能(執行步驟2的指令碼),這時ugnx介面會出現類似卡住的現象(應該實在等待ecilpse命令)

4)切換到ecilpse,然後就可以單步調試執行了,ug介面就會根據指令碼內容變化了。

個人感覺這個ecilpse的開發環境最大的好處,可以進行命令的補全。程式除錯方面感覺並沒有那麼順手,可能是我用的不熟練的原因吧。

下面來一段測試**吧,畫兩個點,然後兩點連成直線,希望對想學習ug-python開發的有用

# nx 10.0.0.24

import pydevd

pydevd.settrace()

import nxopen

import nxopen.uf

mysession=nxopen.session.getsession()

myufsession=nxopen.uf.ufsession.getufsession()

workpart=mysession.parts.work

displaypart=mysession.parts.display

myui=nxopen.ui.getui()

#pt1=nxopen.uf.curve.createpoint([0.,0.,0.])

#pt2=nxopen.uf.curve.createpoint([10.0,10.0,10.0])

coord1= nxopen.point3d(0.0, 0.0, 0.0)

pt1 = workpart.points.createpoint(coord1)

pt1.setvisibility(nxopen.smartobject.visibilityoption.visible)

pointfeaturebuilder1 = workpart.basefeatures.createpointfeaturebuilder(nxopen.features.feature.null)

pointfeaturebuilder1.point = pt1

nxobject1 = pointfeaturebuilder1.commit()

pointfeaturebuilder1.destroy()

coord2=nxopen.point3d(10.0,10.0,10.0)

pt2=workpart.points.createpoint(coord2)

pt2.setvisibility(nxopen.smartobject.visibilityoption.visible)

pointfeaturebuilder1 = workpart.basefeatures.createpointfeaturebuilder(nxopen.features.feature.null)

pointfeaturebuilder1.point = pt2

nxobject2 = pointfeaturebuilder1.commit()

pointfeaturebuilder1.destroy()

#line1=workpart.curves.createline(pt1,pt2)

#line1.setvisibility(nxopen.smartobject.visibilityoption.visible)

associativelinebuilder1 = workpart.basefeatures.createassociativelinebuilder(nxopen.features.associativeline.null)

associativelinebuilder1.startpointoptions = nxopen.features.associativelinebuilder.startoption.point

point10 = workpart.points.createpoint(pt1, nxopen.xform.null, nxopen.smartobject.updateoption.withinmodeling)

associativelinebuilder1.startpoint.value = point10

point11 = workpart.points.createpoint(pt2, nxopen.xform.null, nxopen.smartobject.updateoption.withinmodeling)

associativelinebuilder1.endpoint.value = point11

associativelinebuilder1.endpointoptions = nxopen.features.associativelinebuilder.endoption.point

nxobject3 = associativelinebuilder1.commit()

associativelinebuilder1.destroy()

#print("this is nx test")

what='this is nx test'

mysession.logfile.writeline(what)

mysession.listingwindow.open()

mysession.listingwindow.writefullline(what)

ug二次開發環境配置

一 系統安裝配置 1.1 安裝ug 安裝vs,假設ug安裝目錄 d program files nx10.0 假設vs安裝目錄 d program files microsoft visual studio 10.0 1.2 拷貝d program files nx10.0 ugopen vs fi...

UG二次開發與Visual Studio的配置

環境準備 nx8.0與vs2010配置。1.安裝vs到 1 e software microsoft visual studio 10.0 安裝nx8.0到e software nx8.0 2 拷貝e sofware nx8.0 ugopen vs files vc vcprojects資料夾下所有...

UG二次開發to string的坑

最開始向list傳遞的double資料是這樣的 string out put uf ui open listing window for int i 0 isize i uf ui write listing window out put.data 多次迴圈之後,但是總是出現意料之外的亂碼,除錯檢查...