|
setting custom properties
hello fella's,
im working on a macro that set the suppression and dimensions of parts within an assembly. it pics a part in an assembly and, depending on various external parameters decides what dimensions it should have.
at the moment my code looks like this :
'unsuppress paneel 12
boolstatus = modeldoc2.extension.selectbyid2("vloer-1@koelcel/paneel 12ori-1@vloer", "component", 0, 0, 0, false, 0, nothing, 0)
modeldoc2.editunsuppress2
'set breedte paneel 12
boolstatus = modeldoc2.extension.selectbyid2("br@sketch1@vloer-1@koelcel/paneel 12ori-1@vloer", "dimension", -0.4750047837849, -0.6522639427834, -1.242181926758, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("br@sketch1@paneel 12ori.part")
mydimension.systemvalue = (le / 2) / 1000
'set lengte paneel 12
boolstatus = modeldoc2.extension.selectbyid2("le@sketch1@vloer-1@koelcel/paneel 12ori-1@vloer", "dimension", -1.920808685221, 0.3246203723679, -0.1293965163067, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("le@sketch1@paneel 12ori.part")
mydimension.systemvalue = (br / 1000)
what this does (maybe not the best way of selecting my parts, but the only way i know of) is unsuppress a part, and basically sets its width and lenght .
what i'd like to do is set a (allready existing) custom property (overide the value) on the selected/current part. (thus beeing able to pass on a value relevant to the givin' dimensions)
big thanks for good advice in advance !!
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
quick and dirty method :
modeldoc2.setcustominfo2("", "custompropname", "valuehere")
thanks for your reply luke,
but i'm getting some errors on using it the way i'm trying too ...
when i use it without the brackets, it gives me an compile error :
see image below :
when i remove the brackets and pass it on like that, it gives me an 438 run-time error ?
see image below:
smack me over the head and tell me what i'm doing wrong here ? ^_^
regards,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
it seems that luke may have (very uncharacteristically) led you slightly astray.
modeldoc2. custominfo2(configuration, fieldname) = value
use "" as the configuration argument for non-config-specific properties.
i'll get you eh steve, if it's the last thing i dooooo!
ah yes forgot vba doesnt use the set prefix, but is just as josh stated.
wow, bit of a tough weekend here.
so, to check if i get it correctly;
modeldoc2. custominfo2(configuration, fieldname) = value
modeldoc2 obviuosly beeing my sw.activedoc
configuration defining the configuration (mainly "default")
and fieldname = the name of my custom property ? (bomcode)
followed by = value (new value i want to get set into that custom property )
if so, i must be having a real bad weekend as i haven't been able to get this to work in the above context o_o
this is what i made of it :
boolstatus = modeldoc2.extension.selectbyid2("vloer-1@koelcel/paneel 12ori-1@vloer", "component", 0, 0, 0, false, 0, nothing, 0)
modeldoc2.editunsuppress2
modeldoc2. custominfo2("default", "bomcode") = "this is my desired value"
any ideas why ?
kind regards, and many thanks for all the help !
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
option explicit
sub main()
dim swapp as sldworks.sldworks
dim swassy as assemblydoc
dim swmod as sldworks.modeldoc2
dim swmodpart as sldworks.modeldoc2
dim swcustpropmgr as sldworks.custompropertymanager
dim comp as sldworks.component2
dim vs as variant
dim v as variant
dim valin as string
dim bret as boolean
dim tsuppression as swcomponentsuppressionstate_e
set swapp = application.sldworks
set swmod = swapp.activedoc
if swmod.gettype = swdocassembly then
set swassy = swmod
vs = swassy.getcomponents(false)
for each v in vs
set comp = v
tsuppression = comp.getsuppression
comp.setsuppression2 swcomponentfullyresolved
if comp.getmodeldoc.gettype = swdocpart then
set swmodpart = comp.getmodeldoc2
set swcustpropmgr = swmodpart.extension.custompropertymanager("")
swcustpropmgr.delete "bomcode"
' voeg hier je eigen code toe, om waarde van valin te bepalen
valin = "something"
bret = swcustpropmgr.add2("bomcode", swcustominfotext, valin): debug.assert bret
swmodpart.savesilent
end if
comp.setsuppression2 tsuppression
next v
end if
end sub
answer or this way
option explicit
sub main()
dim swapp as sldworks.sldworks
dim swmod as sldworks.modeldoc2
dim swmodpart as sldworks.modeldoc2
dim swcustpropmgr as sldworks.custompropertymanager
dim comp as sldworks.component2
dim valin as string
dim boolstatus as boolean
dim tsuppression as swcomponentsuppressionstate_e
dim swselmgr as sldworks.selectionmgr
set swapp = application.sldworks
set swmod = swapp.activedoc
set swselmgr = swmod.selectionmanager
if swmod.gettype = swdocassembly then
swmod.clearselection2 true
boolstatus = swmod.extension.selectbyid2("vloer-1@koelcel/paneel 12ori-1@vloer", "component", 0, 0, 0, false, 0, nothing, 0)
if swselmgr.getselectedobjectcount = 1 then
set comp = swselmgr.getselectedobjectscomponent(1)
tsuppression = comp.getsuppression
comp.setsuppression2 swcomponentfullyresolved
if comp.getmodeldoc.gettype = swdocpart then
set swmodpart = comp.getmodeldoc2
set swcustpropmgr = swmodpart.extension.custompropertymanager("")
swcustpropmgr.delete "bomcode"
' voeg hier je eigen code toe, om waarde van valin te bepalen
valin = "xyz"
boolstatus = swcustpropmgr.add2("bomcode", swcustominfotext, valin): debug.assert boolstatus
swmodpart.savesilent
end if
comp.setsuppression2 tsuppression
end if
end if
end sub
are you really intending to do configuration-specific custom properties, or overall file custom properties? in the solidworks dialog for custom properties there are two tabs for custom properties. if you're wanting to set the overall custom property then you use "" (empty string) as the configuration argument. if you actually want to set the property on the configuration-specific tab you specify a configuration name. the modeldoc2::custominfo2 way of doing this will only modify an existing property. it will not create it if it doesn't exist. so if you're trying to modify an existing overall custom property but you're specifying a configuration it won't work.
i'll get you eh steve, if it's the last thing i dooooo!
josh , i'm looking to change overall custom properties, not config specific ones.
but ! looks like i've managed to do so with the help of ivana's suggestions !
my code looks somewhat like this :
'suppress paneel 12
boolstatus = modeldoc2.extension.selectbyid2(assy & "-1@koelcel/paneel 12" & zijde & "-1@" & assy, "component", 0, 0, 0, false, 0, nothing, 0)
modeldoc2.editsuppress2
'set de linear pattern op 1 (= "suppress")
boolstatus = modeldoc2.extension.selectbyid2("aantal@aantal 12" & zijde & "@" & assy & "-1@koelcel", "dimension", 1.001142220076, 1.598814364131, -1.549867393685, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("aantal@aantal 12" & zijde & "@" & assy & ".assembly")
mydimension.systemvalue = 1
'set paneel 22 dims
boolstatus = modeldoc2.extension.selectbyid2("br@sketch1@" & assy & "-1@koelcel/paneel 22" & zijde & "-1@" & assy & "", "dimension", 0.2731486656222, 0.6722293903209, 0.1045605506973, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("br@sketch1@paneel 22" & zijde & ".part")
mydimension.systemvalue = maat / 1000
'set paneel 22 paneelcode & bomcode
boolstatus = modeldoc2.extension.selectbyid2(assy & "-1@koelcel/paneel 22" & zijde & "-1@" & assy, "component", 0, 0, 0, false, 0, nothing, 0)
set comp = swselmgr.getselectedobjectscomponent(1)
set swmodpart = comp.getmodeldoc2
set swcustpropmgr = swmodpart.extension.custompropertymanager("")
swcustpropmgr.delete "bomcode"
swcustpropmgr.delete "paneelcode"
valin = paneelafwerking & (ho / 100) & (maat / 100) & "-22"
boolstatus = swcustpropmgr.add2("paneelcode", swcustominfotext, valin) ': debug.assert boolstatus
valin = "'" & paneelafwerking & (ho / 100) & (maat / 100) & "-22','','','','','','',''"
boolstatus = swcustpropmgr.add2("bomcode", swcustominfotext, valin) ': debug.assert boolstatus
'swmodpart.savesilent
'excuse me for the long lines above... might affect read-ability .
ivana, het werkt ! hartelijke dank voor de info en hulp ! je bent een reddende engel ! ^_^
thanks all, looks like i'm out of this pickle aswell !
greatfull regards,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
quick |
|