Cancel
Showing results for 
Search instead for 
Did you mean: 

Select part in tree

Valued Contributor
Valued Contributor

Hello,

 

So I have just installed ST10 and was using the new Open drawing command,

I have been using my own macro to open the drawing from a part or assembly file for some time.

In my macro if the draft is not found it automatically runs the create a new draft command to save a bit of effort.

 

I now also see that the new built in command uses the windows indexed links ( I think) so it fails to find the draft all of the time.  So going to continue to use my own.

However  the built in command does something I likeSmiley Happy , i can open the draft by just selecting the file in the tree... and not just the active document.

 

So I am trying to update my own!  

and here I run into an issue

 

If the part is in the top level assembly i can find it with:-

 

objApp.ActiveSelectSet.Item(1).OccurrenceFileName

 

but if its in a sub assembly i need to use :-

 

objApp.ActiveSelectSet.Item(1).Object.OccurrenceFileName

 

and using the wrong one fails so I cannot seem to test for isnothing.

 

Using the excellent spy i can see;

snip1.JPG

 

 

snip2.JPG

 

 a crude way of testing..  it runs if I comment out the wrong "test" line.

Snip3.JPG

 I was using the OccurrenceFileName for testing but will prefer to use the OccurrenceDocument reference

for .path and .Fullname etc

 

 The question is how should I be finding the filename / path from the selected item.

 

Sorry that seemed harder to explain than necessary.

 

Thanks for your help 

Regards Kevin

 

 

 

7 REPLIES 7

Re: Select part in tree

Legend
Legend
if objApp.ActiveSelectSet.Item(1).Type = igReference then
objApp.ActiveSelectSet.Item(1).Object.OccurrenceFileName
.....
regards
Gerald

Re: Select part in tree

Valued Contributor
Valued Contributor
Thank you so much for your help Gerald , that worked a treat.

Regards Kevin

Re: Select part in tree

Pioneer
Pioneer

@kevin_parker would you be so kind to post the updated Macro?  (We're still on ST7).

Btw, does it matter what folder the files are saved in?  We use a server to store the files, and the top level assembly is in a different folder than the subassemblies/parts.

Our drawings are, however, usually stored in the same folder as its assy/part.

sryp

ST7 Classic MP0 | Win7

Re: Select part in tree

Valued Contributor
Valued Contributor

Hello,

 

I think I have attached the latest version I have.

I can attach the source code later if it helps, ( written in VB)

 

The macro expects that a file is open in SE.

it looks in the same directory as the part / assy for a dft used by the part or assy.

if one is not found it runs the create a draft from model command.

 

I only use one draft per part so it only looks for the first one it finds, 

 

Hope it helps, 

 

I still use it, as its more reliable than the one provided in ST9+ 

Re: Select part in tree

Builder
Builder

@kevin_parker 

Hi~

I am in the same situation as your question.
If you don't mind, can you show me the code of how it was solved?

 

Thankyou

Re: Select part in tree

Valued Contributor
Valued Contributor

Hello Hclee1,

 

I have attached the original files,

 

I wrote this some time ago now in VB, so be gentle with the comments..

i used VB studio, the free version

 

I still use the app daily as it just works, for my needs.

 

When the exe is run with a file open it checks for any linked draft files and opens the first one,

if a draft file is not found it runs the create new draft command.

if a part is highlighted in an assembly then it opens the draft for the highlighted part.

 

Regards Kevin

 

Re: Select part in tree

Builder
Builder

@kevin_parker 

Thank you for your reply and code.
The main issues were choosing the Occurrence in the assembly and the Occurrence in the sub-accessory included in the assembly.
Your code has been very helpful.
Thank you very much.