• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

read custom properties via macro

  • Thread starter Thread starter EM82
  • Start date Start date

EM82

Guest
Good morning.
I just approached the macro of solidworks bees, and I have to deal with a problem for which I would need clarification. I press that I am using premium solidworks 2013.
would be possible, through a macro, read and possibly modify the custom properties of a part file (.sldprt) that is not open at this time? I ask why at this moment I know how to read the properties of the currently active file, but I may need to access the properties of other parts as well.
Thank you very much.
 
it is possible to access custom properties of unopened files both in reading and writing.
use the swdocumentmgr bees (document manager), in the bees manual find all the documentation and useful examples.
 
it is possible to access custom properties of unopened files both in reading and writing.
use the swdocumentmgr bees (document manager), in the bees manual find all the documentation and useful examples.
So, if I understand correctly, I would need a licence key to perform the above operation... Am I wrong?
 
Yes, this has always been. Just ask it free of charge through the site, you have to register, attention that from the 2014 version seems to me the license does not open higher versions and every year it is required new accordingly.
 
the fact is, by making an attempt now, I managed to access the custom properties of a part I had opened without using the license key... And then, going to see the manual bees, I saw that the types of files you used did not match those I used.
I attach what I wrote:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim config as sldworks.configuration
dim cuspropmgr as sldworks.custompropertymanager

sub main()

set swapp = application.sldworks
set swmodel = swapp.activedoc
set config = swmodel.getactiveconfiguration

set cuspropmgr = config.custompropertymanager
set part = swapp.activedoc
set fso = createobject("scripting.filesystemobject")
sfilename = "d:/enrico/archive 3dfloor/sldprt"

set part = swapp.activatedoc3("sfilename", false, 0, 0)
svalue = cuspropmgr.get("title")

msgbox ("okay: " & svalue) ' I am given the value "title" of the currently open part,
'and not of "floor.sldprt"

end
 
the fact is, by making an attempt now, I managed to access the custom properties of a part I had opened without using the license key... And then, going to see the manual bees, I saw that the types of files you used did not match those I used.
premise:
the code
swapp.activatedoc3("sfilename", false, 0, 0)
assumes that the floor file is open in another window, otherwise it does not change window chart,
in case the file is closed is not the right command string to open the file "floor", but the correct code line is as follows:

set swmodel = swapp.opendoc6(sdocfilename, swdocpart, swopendocoptions_silent
, ", nerrors, nwarnings)


in your code:
- the cuspropmgr object gives you access to custom properties, passing modeldoc2
- if you see the modeldoc2 in the video file at that time (e.g. "pippo.sldprt") and then change the graphics window by activating "floor.sldprt", the modeldoc2 object was set to the file "pippo" and then in cascade the property "title" that revenues is referred to the file "pippo".

in case you have the floor file opened in another graphic window, the code should be as follows:

dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim config as sldworks.configuration
dim cuspropmgr as sldworks.custompropertymanager
dim sfilename as string
dim boolstatus as boolean
dim longstatus as long, longwarnings as long

sub main()
set swapp = application.sldworks

dim sfilename as string
sfilename = "floor.sldprt"
'change window graphics and bring me to floor
swapp.activatedoc2 sfilename false, longstatus
set swmodel = swapp.activedoc
set config = swmodel.getactiveconfiguration
set cuspropmgr = config.custompropertymanager
svalue = cuspropmgr.get("title")
msgbox ("okay: " & svalue)

end

in case the floor file was closed the code would be as follows:

dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim config as sldworks.configuration
dim cuspropmgr as sldworks.custompropertymanager
dim sfilename as string
dim boolstatus as boolean
dim longstatus as long, longwarnings as long

sub main()
set swapp = application.sldworks
set swmodel = swapp.activedoc
' open
sfilename = "d:\enrico\archive 3d\floor.sldprt"
set swmodel = swapp.opendoc6(sfilename 1, 0, "", longstatus, longwarnings)
swapp.activatedoc2 "floor.sldprt", false, longstatus
set config = swmodel.getactiveconfiguration
set cuspropmgr = config.custompropertymanager
svalue = cuspropmgr.get("title")
msgbox ("okay: " & svalue)

end

If you do not want to physically open the file in solidworks (which is what I had understood at first), you must use the bees swdocumentmgr (document manager) as described at the beginning of the discussion.
with this system you could also access not having solidworks installed
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top