几何尺寸与公差论坛

 找回密码
 注册
查看: 1180|回复: 0

【转帖】copy an existent sketch into a macro

[复制链接]
发表于 2009-4-12 20:31:03 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 09:23 , Processed in 0.036821 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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