几何尺寸与公差论坛

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

【转帖】how to ask user for poin

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

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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