几何尺寸与公差论坛

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

【转帖】how to draw rectangle of size less than millimeter

[复制链接]
发表于 2009-4-12 21:15:17 | 显示全部楼层 |阅读模式
how to draw rectangle of size less than millimeter
i have written this in my macro
'
part.sketchrectangle 0, 0, 0, 0.001, 0.1, 0, 1 ' (rectangle 1*100 mm)
'
it works fine but if i change the widht of the rectangle to be less tha millimeter the macro wont draw the rectangle
for example like this
'
part.sketchrectangle 0, 0, 0, 0.0001, 0.1, 0, 1 ' (rectangle 0.1*100 mm)
'
what do i do wrong?
even if i record the macro to draw a very thin rectangle, the recorded macro wont work. is this some already well known problem? i tried to find a solution by googleing but didnt get the asnwer. thanks mates in advance
hi,
you can use the following functions
sketchmanager:: addtodb
sketchmanager:: displaywhenadded
essentially before you create your sketch you add it to the database to avoid grid and entity snapping etc.
in code it will look something like this:
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
modeldoc.sketchmanager.addtodb = true
modeldoc.sketchmanager.displaywhenadded = false
'here do your sketch
'
modeldoc.sketchmanager.addtodb = false
modeldoc.sketchmanager.displaywhenadded = true
end sub
cheers,
--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
edited: 03/10/2009 at 05:29 am by stavros antoniou
thanks for ur quick reply..
it says "object doesn't support this property or method"
bug is on line "modeldoc.sketchmanager.addtodb = true"
code
--------------------
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
dim part as object
dim selmgr as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
modeldoc.sketchmanager.addtodb = true
modeldoc.sketchmanager.displaywhenadded = false
set part = swapp.activedoc
set selmgr = part.selectionmanager
boolstatus = part.extension.selectbyid2("front", "plane", 0, 0, 0, false, 0, nothing, 0)
part.sketchrectangle 0, 0, 0, 0.002, 0.1, 0, 1
what version of solidworks are you using?
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
2007 sp5
i also thought that it might be some new feature from more recent version of sw. do ya think thats the reason
yes its availability is from 2008 version
deepak gupta
sw2007 sp5.0
sw2009 sp2.1
ok,
use the following lines instead:
code
--------------------
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
'dim part as object
dim selmgr as sldworks.selectionmgr
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
set selmgr = modeldoc.selectionmanager
modeldoc.setaddtodb true
modeldoc.setdisplaywhenadded false
'set part = swapp.activedoc ' this line can go
boolstatus = modeldoc.extension.selectbyid2("front", "plane", 0, 0, 0, false, 0, nothing, 0)
modeldoc.insertsketch2 true 'to insert sketch
modeldoc.sketchrectangle 0, 0, 0, 0.002, 0.1, 0, 1
modeldoc.setaddtodb false
modeldoc.setdisplaywhenadded true
modeldoc.insertsketch2 true 'to exit sketch
i have added some changes to your code too. you can get rid of the part object as it can be replaced by the modeldoc object. also its good practice to use the insert sketch function before creating a sketch as seen above
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
thanks!
now it works! so whats the purpose of these lines:
modeldoc.setaddtodb true
modeldoc.setdisplaywhenadded false
why didn't my original code work with <1mm values. it still worked fine with >1mm values.
i'm not a real programmer, so this may be a bit paranoid, but i would recommend against using modeldoc as the name of a variable. while the declaration "dim modeldoc as sldworks.modeldoc2" should take precedence, modeldoc itself is also a valid (although obsoleted) object type in the solidworks api. i always try to name my variables with a name that isn't already used somewhere.
for example, let's say i'm writing a macro that works on a part and an assembly document. of course, i need a modeldoc2 object for each of those. if i decided to use
dim partdoc as sldworks.modeldoc2
dim assemblydoc as sldworks.modeldoc2
that could be a problem. the reason is that partdoc and assemblydoc are both object types in the api. if i later needed to use any functionality of those objects i would have to go and change my variable names.
as far as the purpose of the two lines, stavros explained that in his first post:
"essentially before you create your sketch you add it to the database to avoid grid and entity snapping etc."
when you create sketch entities through the api without using these lines, solidworks behaves just like you were sketching them with a mouse. it will go ahead and add relations and snaps, etc. as though you had clicked the mouse. depending on your zoom level, if 1mm is within the snap distance then it will "snap" that second rectangle corner coincident with the first corner. then it goes "whoa, you can't do that" and the rectangle isn't made.
i'll get you eh steve, if it's the last thing i dooooo!
ok thanks! now i understand.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 09:03 , Processed in 0.038005 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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