几何尺寸与公差论坛------致力于产品几何量公差标准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-13, 11:54 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how to ask user for poin

how to ask user for point?
i'm sure there is an easy way, but without an api object model map in front of me to find the child call i'm lost. i remember in autocad prompting a user for a pick point to insert a block doing this:
blocksipnt = thisdrawing.utility.getpoint(, "pick point for " & blkitem1 & ": ")
but i'm having a problem in solidworks doing the same. any help is very appreciated.
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
with it being 3d space it isn't that simple in sw. what are you trying to get a point for? you options are to let the user select a point, edge or face of a solid body or reference object, or to type in the x,y,z.
there really isn't a similar single api call like getting a pickpoint like there is in autocad. but you can accomplish the same thing. the trick is the prompt.
if you are dealing with blocks in a 2d drawing, use the selection manager. the getselectionpoint2 method will return a variant array of three doubles for x, y and z. since you're in a drawing, just ignore the z value.
'----------------macro code------------
sub main()
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim selmgr as sldworks.selectionmgr
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
dim loc as variant
loc = selmgr.getselectionpoint2(1, -1)
debug.print "x = " & loc(0)
debug.print "y = " & loc(1)
debug.print "z = " & loc(2)
end sub
'-------
the code above works post-selection. so if you want to prompt the user, you have to show them a modeless form that doesn't prevent them from selecting. you can't just use msgbox since it is modal and will not allow the user to do anything in solidworks until it is acted on (if you are dealing with a macro). otherwise, make use of a property manager page so you can get selections while running and prompting the user.
mike spens
"automating solidworks using macros"
leap frog leap pad x64
hi luke,
need the point for inserting a 2d block that will be created from that point on the fly. this will be a stamp using annotations and be used in both 2d and 3d space. trying to get a random point in space could be on the active plane for 3d but not associated to any element. in autocad this was permitted in both 2d and 3d space. i already created this in autocad vba and i'm converting to solidworks vba. the final will be 3 vba routines, 1 for the initial draft stamp, 1 for redefining the solidworks plot/print to update the draft stamp or release stamp print date and who printed it and 1 to replace the draft stamp with a release stamp. this will allow one to digitally stamp all layout tabs and print the stamp object imbedded on the face of the print out and have it be updated everytime. i'm thinking that i could have the routine prompt the user to insert a point, then capture the point coordinates as an input, remove the point and use those coordinates to construct the block around. is this possible?
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
getselectionpoint2 will return a value only if you have selected something. in a drawing this works well since you are selecting the drawing sheet. if you are trying to place something in open space in a part or assembly, it could be tough. i haven't explored this completely, but there are mouse events you could capture like mouselbtnupnotify that returns the x, y point of the mouse, but it is relative to the document's window. i haven't figured out if you can transpose that into model x,y coordinates.
you could activate a 3d sketch with your code and have the user draw a sketch point as the pick method. this might actually behave a little more like the pickpoint in autocad.
mike spens
"automating solidworks using macros"
leap frog leap pad x64
have a question. when you envoke the point command from the sketch bar and then its prompts you to place the point, how is that operation performed by solidworks? i think this is all i need is that operation. then i could capture that point's coords, delete the point and use the coords values to position the block from. this way the block is not associated to any element.
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
came up with this to capture an existing point's xyz, now just need to prompt for a point to be placed prior to capture.
'----------
sub main()
on error resume next
dim swapp as object
dim part as object
dim thesketchpoint as variant
dim sketchpointarray() as variant
dim pointcount as integer
dim xvalue as double
dim yvalue as double
dim zvalue as double
dim mtrval as double
set swapp = application.sldworks
set part = swapp.activedoc
set thesketch = part.getactivesketch2
mtrval = 0.0254 ' convert all meter values to inches
thesketchpoint = thesketch.getsketchpoints2
if ubound(thesketchpoint) = 0 then
msgbox "no points found"
end
else
pointcount = ubound(thesketchpoint) + 1
end if
for i = 0 to (pointcount - 1)
' get the coordinates and assign to array
redim preserve sketchpointarray(pointcount - 1, 2)
sketchpointarray(i, 0) = thesketchpoint(i).x
sketchpointarray(i, 1) = thesketchpoint(i).y
sketchpointarray(i, 2) = thesketchpoint(i).z
' convert to inches
xvalue = sketchpointarray(i, 0) / mtrval
yvalue = sketchpointarray(i, 1) / mtrval
zvalue = sketchpointarray(i, 2) / mtrval
' do something with data
msgstr = msgstr & "point: " & i + 1 & vbcrlf & "x = " & xvalue & vbcrlf & "y = " & yvalue & vbcrlf & "z = " & zvalue & vbcrlf & vbcrlf
next i
msgbox msgstr
end sub
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
oops, had to make a correction:
if ubound(thesketchpoint) < 0 then 'count starts at 0 not 1
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
how do you get the point to delete?
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
you first select it, then call either modeldoc2.editdelete or modeldocextension.deleteselection2. you have options with deleteselection2, none with editdelete.
to select the sketch point you can use sketchpoint.select4 method (you already have the sketch point). there is an example titled "create plane thru 3 points in-context example" that covers point selection using this method. hope that helps.
mike spens
"automating solidworks using macros"
leap frog leap pad x64
thanks mike for all your help. here's what i have so far. this will capture all existing points, store thier positions in an array and remove the points. now to work out the prompting user for insertion point locations.
'----------
sub main()
on error resume next
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swmodeldocext as sldworks.modeldocextension
dim swselmgr as sldworks.selectionmgr
dim swseldata as sldworks.selectdata
dim thesketchpoint as variant
dim sketchpointarray() as variant
dim pointcount as integer
dim xvalue as double
dim yvalue as double
dim zvalue as double
dim mtrval as double
dim bret as boolean
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swmodeldocext = swmodel.extension
set swselmgr = swmodel.selectionmanager
set swseldata = swselmgr.createselectdata
thesketchpoint = swmodel.getactivesketch2.getsketchpoints2
mtrval = 0.0254 ' convert all meter values to inches
if ubound(thesketchpoint) < 0 then 'count starts at 0 not 1
msgbox "no points found"
end
else
pointcount = ubound(thesketchpoint) + 1
end if
for i = 0 to (pointcount - 1)
' get the coordinates and assign to array
redim preserve sketchpointarray(pointcount - 1, 2)
sketchpointarray(i, 0) = thesketchpoint(i).x
sketchpointarray(i, 1) = thesketchpoint(i).y
sketchpointarray(i, 2) = thesketchpoint(i).z
' do something with data
' convert to inches and prep for screen
xvalue = sketchpointarray(i, 0) / mtrval
yvalue = sketchpointarray(i, 1) / mtrval
zvalue = sketchpointarray(i, 2) / mtrval
msgstr = msgstr & "point: " & i + 1 & vbcrlf & "x = " & xvalue & vbcrlf & "y = " & yvalue & vbcrlf & "z = " & zvalue & vbcrlf & vbcrlf
' remove the point
bret = thesketchpoint(i).select4(true, swseldata)
swmodeldocext.deleteselection2 (swconst.swdelete_absorbed)
next i
msgbox msgstr ' pop to screen
end sub
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】batch w user input macro yang686526 SolidWorks二次开发 0 2009-04-12 08:17 PM
pc-dmis 3.6 mr1 发布了 huangyhg PC-DMIS 0 2009-04-06 08:46 PM
【转帖】dataage user manual - c-dmis user forum.txt huangyhg PC-DMIS 0 2009-04-06 06:55 PM


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


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