Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Get handle of Modeldoc2 without opening. 1

Status
Not open for further replies.

bguenther

Mechanical
Nov 3, 2008
37
Hi,
I am hopeing someone can help me with this.
I am looping through an assemblies parts getting some information about each part, which works fine. What i am not able to do is specify which part I want to have the handle on. If the part that I currently have the on is a mirrored part then I need to get the handle on the part that the mirrored part is referenced to, then move the handle back to the mirrored part and continue looping the assembly. I do not want to open the part in its own window.
I want swModelTemp to equal PartName. swModelTemp is declared as ModelDoc2 and PartName is declared as String.

I have tried many different ways to do this but have had no luck.
Thanks for any help.
 
Replies continue below

Recommended for you

Just to clarify/sum up:

You know the filename (and path?) of the ModelDoc that you want, stored as a string in variable PartName.

You want to get the ModelDoc object corresponding to that file (which may or may not be open already, possibly in its own window or possibly in the background), but you don't want it to open in its own window.

Is that correct?

-handleman, CSWP (The new, easy test)
 
Partname is the file name and the path I want the handle on. And there are no parts open just the assembly. PartName will only be one of the assembly parts, not parts that are not in the open assembly.

So if it worked if would like to say: swModelTemp = PartName
 
Have you tried SldWorks::OpenDoc6 or OpenDoc7?

-handleman, CSWP (The new, easy test)
 
Yes i did try them. If i use them then the part opens in its own window. The reason I don't want to open the part in its own window is, it is alot slower because it has to load, update then close the part yet.
 
What do you want to do with the ModelDoc object once you get it? You can't get a ModelDoc object without loading the model. A ModelDoc object does not represent a file in storage somewhere, it represents a SolidWorks document that has been loaded into memory. If you don't want the model to have its own window then you can set its "Visible" property to False, but you can't avoid loading the part into memory.

If you only want to access custom properties, google DSOFile.

-handleman, CSWP (The new, easy test)
 
ok. Let me try and give an example then.

varComponents = swAss.GetComponents(False)
For i = 0 To swAss.GetComponentCount(False) - 1
Set swComponent = varComponents(i)

Set swModelTemp = swComponent.GetModelDoc

Next i

Now inside that for loop i could loop through the features of swModelTemp without loading swModelTemp.

Now how could I specify which component swModelTemp is suppose to be ?
 
No, you can't. If you are looping through the features of swModelTemp, then swModelTemp is loaded. When you open an assembly, all the (non-suppressed) components of that assembly are loaded into memory, although they don't have their own window. If a document is not already loaded into memory I don't know of any way to get a pointer to it without using one of the OpenDoc functions.

You can set the SldWorks::DocumentVisible flag to False prior to using OpenDoc. That will load the document into memory without giving it its own window. Just be sure to set it back to True immediately, or files that the user tries to open later will not be visible. You should also have an error handling routine to set it back to True in case the macro crashes during opening of the file. You could have found this information in the API help for OpenDoc6 or OpenDoc7.



-handleman, CSWP (The new, easy test)
 
Thanks handleman,

I did not fully understand how that worked. I had previously looked in the SW help for opening parts but did not understand it right. That works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor