×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Get handle of Modeldoc2 without opening.

Get handle of Modeldoc2 without opening.

Get handle of Modeldoc2 without opening.

(OP)
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.
  

RE: Get handle of Modeldoc2 without opening.

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)

RE: Get handle of Modeldoc2 without opening.

(OP)
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

RE: Get handle of Modeldoc2 without opening.

Have you tried SldWorks::OpenDoc6 or OpenDoc7?

-handleman, CSWP (The new, easy test)

RE: Get handle of Modeldoc2 without opening.

(OP)
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.

RE: Get handle of Modeldoc2 without opening.

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)

RE: Get handle of Modeldoc2 without opening.

(OP)
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 ?  

RE: Get handle of Modeldoc2 without opening.

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)

RE: Get handle of Modeldoc2 without opening.

(OP)
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.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources