Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document visibility in macro 1

Status
Not open for further replies.

gp13

Mechanical
Sep 27, 2007
156
I have a macro that I made in SW2008 that do not seem to work in SW2009. The problem seems to lie within the following line of code:

visibility = swApp.DocumentVisible(False, swDocPart)

When I run the macro, I get an error that says "Compile error: Expected Function or variable" and it highlights the ".DocumentVisible" part of the code.

I know it used to work, and it does not appear that the method is obsolete, but I cannot figure this out. I use the 2008 help file still, because the 2009 one does not make sense to me.

My goal is to open a part without loading it into memory to read a custom property on the "Configuration Specific" tab. I want to run this macro against about 1000 parts, so loading them into memory just to read one property is very unnecessary.

Thanks,
Matt
 
Replies continue below

Recommended for you

Not sure about your specific issue, but your basic premise is flawed. You cannot "open a part without loading it into memory" in SolidWorks. Even if it doesn't have its own window, it loads it into memory.

What you want to use is the swDocumentMgr.dll interface. It can directly access many parts of the SW file (including configuration-specific custom properties) without opening the file in SW. SW doesn't even have to be running. The macro can run from Excel or even VBScript. You just have to write an email to apisupport@solidworks.com and request a license key to use it. The 2008 API help file even has documentation for it.

-handleman, CSWP (The new, easy test)
 
Here's a quick demo macro I wrote some time ago. I don't remember a whole lot about it. Probably not much error trapping, etc, and some of it may not work. Should be enough there to get you started, though.

-handleman, CSWP (The new, easy test)
 
 http://files.engineering.com/getfile.aspx?folder=107726bb-6baa-4b81-8138-bc2f9dac266c&file=CfgSpecUsingDocMgr.swp
handleman,
Thank you, as usual, for the prompt response.

I guess my wording was a little off. Just to clear up the confusion... I know SW still loads the part, but it is much less intensive on system resources, and therefore much quicker, if it is not loaded as visible. This is from the help file, and is basically I meant to say I was trying to avoid: "Opening a model causes SceneGraph to display the model. SceneGraph uses maps with defaults sizes of 2MB - 3MB for even the simplest model."

I resolved the problem by changing a couple lines of code.
"Dim swApp As SldWorks.SldWorks" changed to"Dim swApp As ISldWorks"
"visibility = swApp.DocumentVisible(False, swDocPART)" changed to "swApp.DocumentVisible False, swDocPART"

Either way, I will definitely try your suggestion. This seems like the ideal solution since it does not have to actually open the file. I already got the info I needed out for now, but I am sure this will come up in the future. This method should save me quite a bit of time.

Thanks again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor