几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 08:31 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】copy an existent sketch into a macro

copy an existent sketch into a macro
i hope somebody can help me with this matter.
i have recorded a macro to build a sketch from the scratch which it has several arcs, lines and trims. turns out, that when i run the macro the trims do not work. the sketch appears with all the lines and arcs without the trims.
therefore, i decide to record a macro to copy and paste this sketch that was built and located in other file. the problem is that when i run the macro the sketch i pasted it does not appears. however, i reviewed the macro and i saw that the arcs, lines i pasted are there.
i run out of options. i wonder if you can tell me another way to do it or perhaps you can tell me if i am missing something in the two processes i applied.
thanks in advance.
maperalia
edited: 11/26/2008 at 05:32 pm by mapea ralia
hello mapea,
if you post your code here then we might be able to spot what might be going wrong.
from your description i am not sure what the issue is.
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
your problem is probably that recording a macro does not insert the insertsketch2 command and so it would all run but no entities appear like you describe. to solve the problem insert a new sketch first. for example this macro will create lines, arcs and trims:
option explicit
dim swapp as sldworks.sldworks
dim part as modeldoc2
dim selmgr as selectionmgr
dim boolstatus as boolean
sub main()
set swapp = application.sldworks
set part = swapp.newdocument("t:\don bur templates\don bur part.prtdot", 0, 0#, 0#)
set part = swapp.activedoc
dim skline as object
part.insertsketch2 true
set skline = part.sketchmanager.createline(-0.04765447668422, 0.03345611650445, 0, 0.01811305857348, 0.04152720419961, 0)
set skline = part.sketchmanager.createline(0.01811305857348, 0.04152720419961, 0, 0.04108861674212, 0.02130074503492, 0)
set skline = part.sketchmanager.createline(0.04108861674212, 0.02130074503492, 0, 0.02310255835212, 8.700939061598e-04, 0)
set skline = part.sketchmanager.createline(0.02310255835212, 8.700939061598e-04, 0, -0.01821627451793, -0.00420061343066, 0)
dim skarc as object
set skarc = part.sketchmanager.createtangentarc(-0.01821627451793, -0.00420061343066, 0, -0.03042280805778, 0.008359388554084, 0, 1)
set skarc = part.sketchmanager.createtangentarc(-0.03042280805778, 0.008359388554084, 0, -0.04334655952766, 0.04888773218875, 0, 1)
boolstatus = part.extension.selectbyid2("arc2", "sketchsegment", 0#, 0#, 0#, false, 0, nothing, 0)
part.sketchmanager.sketchtrim 0, -0.03817705893971, 0.04233658591716, 0
boolstatus = part.extension.selectbyid2("line1", "sketchsegment", 0#, 0#, 0#, false, 0, nothing, 0)
part.sketchmanager.sketchtrim 0, -0.03875144789396, 0.03506371922037, 0
end sub
luke;
thanks for your response and the macro sample. i run it and it is working perfectly. however, i recorded another simple macro macro with one rectangule, circle and trim them. turns out that my trim operation does not work in the macro. i checked the macro and trim statement is there but is not working.
could you please tell me what setup i need to make it work?
thanks
maperalia
the following example works fine:
option explicit
dim swapp as sldworks.sldworks
dim part as modeldoc2
dim selmgr as selectionmgr
dim boolstatus as boolean
sub main()
set swapp = application.sldworks
set part = swapp.newdocument("t:\don bur templates\don bur part.prtdot", 0, 0#, 0#)
set part = swapp.activedoc
part.sketchmanager.createcornerrectangle -0.04076180923369, 0.03242570176417, 0, 0.03563192167712, -0.001861131736405, 0
part.sketchmanager.createcircle -0.01433991733978, 0.01528228501388, 0, -0.004862499595163, -0.01825405501683, 0
part.extension.selectbyid2 "arc1", "sketchsegment", 0#, 0#, 0#, false, 0, nothing, 0
part.sketchmanager.sketchtrim 0, -0.01548869524817, 0.04988413099079, 0
end sub
notice there is no need to create a sketch this time... strange but true
luke;
thanks for the other macro sample. i run it and it is working perfectly. however, i found the problem i have when i create a macro. basically, when i record the macro with trim i got this statement:
boolstatus = part.sketchmanager.sketchtrim(1, 0.005481168671366, 0.05832584950746, 0)
your trim statement you sent is:
part.sketchmanager.sketchtrim 0, -0.01548869524817, 0.04988413099079, 0
therefore, i changed my statements:
1.- by replacing the"1" with "0"
2.- eliminating "boolstatus"
3.- eliminating the parentesis.
after these changes my trims are working.
is there is any way to get the trim statement in the way should be without making the manual changes?. because i will create a sketch with several lines and arcs and then trim them and will be a lot of trim to modify.
thanks.
maperalia
no not really but you don't need to alter it you can leave it with the braces and boolstatus it wont change the operation of the code
luke;
thanks for your response.
in fact, i saved the sketch as a "template.prtdot" and then i recorded a macro to open it. it it working wonderful!!.
however, i have form the i am not able to make it work. basically, the form takes values.
this is the code of my object that i current have:
'#### start object's code ########
public vertical_line as double
public horizontal_line as double
public distance as double
public angle as double
private sub bok_click()
make sure the user is entering numbers and not text
if isnumeric(txtdistance.text) and isnumeric(txtangle.text) then
distance = txtdistance.text
angle = txtangle.text
hide
else
msgbox "you must enter numeric values for all fields"
end if
end sub
'#### end object's code ########
this is the statement i have in my module for the form:
'#### start user form ################################
dim revolvedistance as double
dim revangle as double
dim newform as new frmrevolve
newform.caption = "enter values in inches"
newform.show
revolvedistance = newform.distance / 39.37008
revolveangle = newform.angle / 57.29577951 'converting from radians to
degrees
set newform = nothing
'#### end user form #####################################
however, when i enter the values is not taking it. could you please tell me how to make it run?
thanks.
maperalia
edited: 12/08/2008 at 03:48 pm by mapea ralia
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
Draft International Standard Iso/dis 10303-108 huangyhg ISO standards 2 2007-01-02 12:55 PM


所有的时间均为北京时间。 现在的时间是 06:09 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多