iLogic – In Assembly open drawing by defined Bom Structure

iLogic – In Assembly open drawing by defined Bom Structure

Anonymous
Not applicable
635 Views
5 Replies
Message 1 of 6

iLogic – In Assembly open drawing by defined Bom Structure

Anonymous
Not applicable

Hello everybody,

 

I have a one iLogic rule for open all the drawings in Assembly. I try to implement one more check:

“If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure”.

 

This work great if I have defined BOM Structure in the Part. If I have defined BOM Structure in Assembly, this don‘t working.

 

Untitled.jpg

 

Part of this rule I used for save as in pdf files. From this reason I need to open all the drawings just one time.

 

Maybe any have some solution for this?

With kind regards,

Jernej Puc

 

Sub Main()
    Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    
    Dim oRefDoc As Document
    Dim oDrawDoc As DrawingDocument
    
    For Each oRefDoc In oDoc.AllReferencedDocuments
		
		oBaseName_suffix = System.IO.Path.GetFileName(oRefDoc.FullFileName)
        oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
		oPathAndName_suffix = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName_suffix
        oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName
        If (System.IO.File.Exists(oPathAndName & ".idw")) Then
			oPartDoc = ThisApplication.Documents.Open(oPathAndName_suffix, False)
'		If	oPartDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Or
'			oPartDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or
'			oPartDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
            oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True)
			
		oDrawDoc.Close

        End If
'	End If
    Next
    
End Sub
0 Likes
Accepted solutions (2)
636 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Anonymous.  I'm not sure I fully understand, but it sounds like you only want your rule to effect components within your assembly that are not seen as 'reference' from the perspective of the main assembly.  And since you mentioned the issue with the BOMStructure of each being set causing a problem, I am assuming that you have set some sub-assemblies to 'reference' and therefore do not want that sub-assembly or anything below that sub-assembly to be processed by your code...is that correct?  If so, then I would suggest that you need to change your looping strategy from AllReferencedDocuments (which will process every component at every level independently) to a more 'top - down' approach, like looping through the regular components.  This process will start with only the top level (directly within the main assembly) components.  Then if needed, we can step down into sub-assemblies as needed, when they aren't set to 'reference'.

 

Here is an example of the process I'm talking about that may work for your situation:

Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	'run our custom recursive Sub routine below
	StepDown(oADoc.ComponentDefinition.Occurrences)
	'you could put a 'job's done' type message here
End Sub

Sub OpenDrawing(oCompDoc As Document)
	'your code to open the drawing
	'we already know that this document is not set to 'reference', so no need to check it again
	'specify full path, name, & ext. of drawing
	Dim oDrgName As String = System.IO.Path.ChangeExtension(oCompDoc.FullFileName, ".idw")
	If System.IO.File.Exists(oDrgName) Then
		Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oDrgName, True)
		'<<<< THE REST OF YOUR CODE TO DO SOMETHING WITH THE DRAWING HERE. >>>>
		oDrawDoc.Close
	End If
End Sub

Sub StepDown(oComps As ComponentOccurrences)
	For Each oComp As ComponentOccurrence In oComps
		'if it is set to 'reference', then skip to next component
		If oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then Continue For
		'run the Sub routine above to open the drawing
		OpenDrawing(oComp.Definition.Document)
		'check if it represents an assembly (sub-assembly)
		If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'if it does, run it back through this same Sub again (recursive processing)
			StepDown(oComp.Definition.Occurrences)
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

Anonymous
Not applicable

Dear @WCrihfield,

Thank you very much for your reply with this iLogic rule. You have right. I agree with your thinking.

“I am assuming that you have set some sub-assemblies to 'reference' and therefore do not want that sub-assembly or anything below that sub-assembly to be processed by your code”

Yes definitely I need step down to all Subassemblies if they aren‘t “Reference”.

But here I see one problem which I want to avoid. Because I will use this rule to save as all files in different format (pdf, stp, dxf,...).

I need to open every Drawing just once. In this case now if I have 10 the same part in Assembly, this rule opening 10 times the same drawing. I don‘t wont this.

 

Many thanks for your kindly help!

Jernej

0 Likes
Message 4 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous 

 

Here's a quick update to @WCrihfield's code that will prevent it from opening the drawing more than once.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Class ThisRule

	Shared oList As New ArrayList

	Sub Main
		If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
			MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "WRONG DOCUMENT TYPE")
			Exit Sub
		End If
		
		oList.clear 'clear this list since shared variables stay in memory
		
		Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
		'run our custom recursive Sub routine below
		StepDown(oADoc.ComponentDefinition.Occurrences)

		'you could put a 'job's done' type message here
	End Sub

	Sub OpenDrawing(oCompDoc As Document)
		'your code to open the drawing
		'we already know that this document is not set to 'reference', so no need to check it again
		'specify full path, name, & ext. of drawing
		Dim oDrgName As String = System.IO.Path.ChangeExtension(oCompDoc.FullFileName, ".idw")

		'check list to see if the drawing has 
		'already been opened
		If Not oList.Contains(oDrgName)
			If System.IO.File.Exists(oDrgName) Then
				Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oDrgName, True)
				'add drawing to list
				oList.Add(oDrgName)
				Logger.Info(oDrgName)
				'<<<< THE REST OF YOUR CODE TO DO SOMETHING WITH THE DRAWING HERE. >>>>
				oDrawDoc.Close
			End If
		End If
	End Sub

	Sub StepDown(oComps As ComponentOccurrences)
		For Each oComp As ComponentOccurrence In oComps
			'if it is set to 'reference', then skip to next component
			If oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then Continue For
			'run the Sub routine above to open the drawing
			OpenDrawing(oComp.Definition.Document)
			'check if it represents an assembly (sub-assembly)
			If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
				'if it does, run it back through this same Sub again (recursive processing)
				StepDown(oComp.Definition.Occurrences)
			End If
		Next
	End Sub

End Class

 

EESignature

Message 5 of 6

WCrihfield
Mentor
Mentor

Good catch @Curtis_Waguespack.  I kind of had a feeling I was missing something when I posted it, but shrugged it off at the time.  Your addition is an ingeniously simple & effective way to avoid the issue of reprocessing the same document more than once.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

Anonymous
Not applicable

Thank you very very much to both of you @WCrihfield' and @ for really good solution which is work perfect for my operation. I need exactly this.

 

Many thanks! 🙂

 

With kind regards,

Jernej

 

 

0 Likes