Open Drawing of a Part in an Assembly

Open Drawing of a Part in an Assembly

j_weber
Mentor Mentor
940 Views
3 Replies
Message 1 of 4

Open Drawing of a Part in an Assembly

j_weber
Mentor
Mentor

Hi everybody, 

 

i have an idea and perheps someone can tell me if this is possible or not. 

 

I have an assembly open. 

In the asssembly are part components and sometimes subassemblys with part components

 

My Idea is now to start an iLogic rule, or vba macro. 

then pick a part

after that a drawing opens. 

 

I such for a example and found a little bit where I can pick a part. 

but I can't find something where I open a drawing from the part. 

 

found this as example

 

Dim comps As ObjectCollection
Dim comp As Object

comps = ThisApplication.TransientObjects.CreateObjectCollection

While True
	comp = ThisApplication.CommandManager.Pick(
		SelectionFilterEnum.kAssemblyOccurrenceFilter, 
		"Select a component") 
		
	' If nothing gets selected then we're done	
	If IsNothing(comp) Then Exit While
	
	comps.Add(comp) 
End While

' If there are selected components we can do something
For Each comp In comps
	comp.delete
	
Next

It works and I can pick a part, but I don't know who I can open the drawing from the part. 

I think it must be at the position where comp.delete

 

Hope it is not to strange. 

 

thanks for reading 

 

Jörg

 




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Accepted solutions (1)
941 Views
3 Replies
Replies (3)
Message 2 of 4

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi,

 

Assuming the drawing name has the same name as the part name, and are both located in the same directory :

 

Dim oPartName As String
Dim oPart As ComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Pick a part")
Dim oDrawingName As String 
Dim oPartNameWithoutExtension As String 
Dim oDoc As Document

 oPartName = oPart.ReferencedDocumentDescriptor.FullDocumentName
			
	oPartNameWithoutExtension = Split(oPartName,".ipt")(0)
			
			oDrawingName = oPartNameWithoutExtension & ".idw"
						
				oDoc = ThisApplication.Documents.Open(oDrawingName,True)

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 4

j_weber
Mentor
Mentor

Hi @FINET_Laurent 

 

Great. It works good. 

 

Often my drawings are not in the same folder like the part. 

But when the drawing is in the same folder with the same name, it work perfectly. 

 

thanks a lot. 




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes
Message 4 of 4

fullevent
Advisor
Advisor

Hello Jörg,

 

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

wenn deine Zeichnung nicht im exakt selben Ordner liegt, kann man einen anderen Bereich zum Durchsuchen festlegen?

z.B. den gesamten Workspace durchsuchen inkl. aller Unterordner.

Je mehr Ordner/Dateien durchsucht werden, desto länger dauert natürlich die Prozedur.

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

 

If your drawing is not in the exact same folder, can you specify a different area to browse?

E.g. search the workspace including all subfolders.

 

The more folders/files are scanned, the longer the procedure will take, of course.

 

 

Gruß/regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes