How can I get the Parent Document and the Parent Document Bomstructure of a document?

How can I get the Parent Document and the Parent Document Bomstructure of a document?

checkcheck_master
Advocate Advocate
4,189 Views
12 Replies
Message 1 of 13

How can I get the Parent Document and the Parent Document Bomstructure of a document?

checkcheck_master
Advocate
Advocate

How can I get the Parent Document and the Parent Document Bomstructure of a document?
It's like I'm not getting it right.
It doesn't seem to be a problem in VBA, but it doesn't work in iLogic.
Help. Driving me nuts...

 

 

'sParentDocument_LOG = occ.ParentOccurrence.Definition.Document.ToString	' Gives System.__ComObject			
			'sParentDocument_LOG = occ.ParentOccurrence.Definition.Document ' Gives nothing 
			'sParentDocument_LOG = oDoc.Parent.ToString ' Gives System.__ComObject
			'sParentDocument_LOG = oDoc.Parent.ComponentDefinition.document.fullfilename ' Gives nothing 
			'sParentDocument_LOG = occ.Parent.Document ' Gives nothing 
			'sParentDocument_LOG = occ.Parent.Document.ToString ' Gives System.__ComObject
			'sParentDocument_LOG = oDoc.Parent.Document.ToString ' Gives nothing 
			'sParentDocument_LOG = oDoc.ParentOccurrence.Document.ToString ' Gives nothing 			
			'sParentDocument_LOG = oDoc.ParentOccurrence.Document ' Gives nothing 
			'sParentDocument_LOG = oDoc.Parent ' Gives nothing 
			'sParentDocument_LOG = occ.ParentOccurrence.ToString ' Gives System.__ComObject
			'sParentDocument_LOG = occ.ParentOccurrence.fullfilename ' Gives nothing 
			'sParentDocument_LOG = oDoc.Parent.fullfilename ' Gives nothing 
			'sParentDocument = oDoc.Parent.fullfilename ' Gives nothing 
			
				' Poging on te kijken of het uitmaakt hoe ComponentDefinition wordt gekregen
				'If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then							
				'	Dim assemDoc As AssemblyDocument = doc							
				'	'params = assemDoc.ComponentDefinition.Parameters
				'	sParentDocument = assemDoc.ComponentDefinition.Document ' Gives nothing 
				'	sParentDocument = assemDoc.Parent ' Gives nothing 
				'	sParentDocument = assemDoc.Parent.document ' Gives nothing
				'	sParentDocument = assemDoc.Parent.ComponentDefinition.Document
				
				'ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then							
				'	Dim partDoc As PartDocument = doc							
				'	'params = partDoc.ComponentDefinition.Parameters							
				'	sParentDocument = partDoc.ComponentDefinition.Document ' Gives nothing 
				'	sParentDocument = partDoc.Parent ' Gives nothing 
				'	sParentDocument = partDoc.Parent.document ' Gives nothing 
				'	sParentDocument = partDoc.Parent.ComponentDefinition.Document
				'End If			
				''Dim userparams As UserParameters = params.UserParameters			

 

 

0 Likes
4,190 Views
12 Replies
Replies (12)
Message 2 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

Assuming occ is a ComponentOccurrence:

- occ.Parent returns an AssemblyComponentDefinitionObject (occ.Parent.ToString returns System._ComObject)

- occ.Parent.Document returns an AssemblyDocumentObject (occ.Parent.Document.ToString returns System._ComObject)

- occ.Parent.Document.FullFileName returns a string unless the document is not saved for the first time, then returns an empty string)

- occ.Parent.Document.FullDocumentName returns a string with the full document name (including active model state)

- occ.Parent.BOMStructure returns a BOMstructureEnum with the BOM structure

 

Dim AssDoc As Inventor.AssemblyDocument = ThisDoc.Document
Dim occ As Inventor.ComponentOccurrence
For Each occ In oAssDoc.ComponentDefinition.Occurrences
	Logger.Debug (occ.Name )
	Logger.Debug(occ.Parent.ToString)
	Logger.Debug(occ.Parent.Document.ToString)
	Logger.Debug(occ.Parent.Document.FullFileName)
	Logger.Debug(occ.Parent.Document.FullDocumentName)
	Logger.Debug(occ.Parent.BOMStructure.ToString)
	Logger.Debug("------------------------------------")
Next

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 13

checkcheck_master
Advocate
Advocate
Great Krieg, I'll check it out right away.
I would also like to know where to find this, could I just get it from the API help?
0 Likes
Message 4 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

Yes, you can find this information in the API help. But it's just like Google. If you don't know the one correct word to search for, you won't get the result you need.

The most comfortable way is to write a little snippet in the VBA editor. Make the Watch window visible. Then set a breakpoint somewhere in the script. Rightclick on the variable you want to watch and add a watch. If your snippet stops at the breakpoint you can see the current value of your variable in watch window. Depending on the type you can expand the watch to see underlying informations. iLogic doesn't have this capabilities until now and Visual Studio is a bit more complicated initial work to get the same results.

The "disadvantages" are, you can not see methods in the watch window, only properties. And you need to use VBA language, which is strongly limited compared to VB.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 13

checkcheck_master
Advocate
Advocate

Thanks for the tips Krieg.


Could you please take a look at the attached code and say something about how I handle variables?
I think I'm doing it too much and I'm missing the object-oriented principle.
Eg: I suppose if you pass oDoc as a document you will extract a property in the receiving sub instead of bothering to define it globally. Is that assumption correct?

0 Likes
Message 6 of 13

checkcheck_master
Advocate
Advocate

Hi Krieg.
See the two rules attached.
The titles speak for themselves.
One goes through the browsers pane and then the Parent Documents are not what they should be.
The text file in the attachment shows this well, all components refer to the main assembly.
The rule based on Inventor.AssemblyDocument works fine.
Although it takes longer to cycle through the browser pane, especially a first time, I like the fact that the sequence conforms to the browser pane.
Do I have to use another method to get the parent document out correctly or do you recommend using Inventor.AssemblyDocument for some or other reason?

0 Likes
Message 7 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

It depends where the property value is used thereafter. If only used in the receiving sub, it should not be defined in class context or created in the sending sub. I try to use always the smallest possible context.

You define the variable oDirChar as public writeable variable. As the class ThisRule is private, the public varaible is not accessable from outside. But it should be:

a) private, so all subs and functions inside the class can access it

b) readonly, cause you don't want to change it per runtime

You should try to split your code in more smaller subs and functions if possible. It's easier to read and understand. In this subs and functions you can add some prechecks and error handling. I see a lot of codeparts where exceptions could raise and there is no reaction on this. For example, you check if your logfile exist. If not, you try to create a new one. But if that fails for any reason, the exception will be catched silently and your code proceed. This will lead to an exception the next time you try to write to this non existing file and your rule crashes.

 

The native objects of first level browser nodes should be ComponentOccurrence. The parent is the AssemblyComponentDefinition of the main assembly. In all deeper levels the native objects should be of type ComponentOccurrenceProxy. If so, you can check for the ComponentOccurrenceProxy.ContainingOccurrence property returning the parent occurrence or occurrenceproxy. The Definition property of those returns the assembly component definition you expect.

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 8 of 13

checkcheck_master
Advocate
Advocate

Thank you Krieg.
Since my last post I have been very busy and have tried to process your advice in the code, see attachment.
I now have a burning question.
It is possible to get a neat overview based on the BOMView and to fill the dictionaries with the categories.
Next I want to grab the keys of the dictionaries and determine the totals of those assemblies and process that in a separate folder.
Actually the procedure is the same just a level deeper.
How would you approach that?
I think recursively loop through the BOMView of that particular assembly and add up the totals from that.
Can I do that in a temporary dictionary that only lives within that sub to get that overview?

So I'm struggling with ProcessBOMRowsRecursively for such a separate assembly.

Check the logfile at the end for an overview what is happening.

0 Likes
Message 9 of 13

checkcheck_master
Advocate
Advocate

Hi Krieg.
I partly figured out why it didn't work.
After these lines, the code will not continue without a message:

' This let the code stops without warning, not comes further the 'End if'...
				' Substract the Quantity of each Part and Assembly and store the value in their Dictionaryies
				Try
					If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then					
						DictionaryWeldments(oDoc.FullFileName) -= strTotalQty				
					ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then				
						DictionaryParts(oDoc.FullFileName) -= strTotalQty				
					End If	
				Catch ex As IOException
					If MsgBox("Exception: " & ex.StackTrace & vbNewLine & "Continue?", vbYesNo & vbCritical, "InventorPLUS") = vbNo Then Exit Sub
				End Try

Why I don't understand yet, but I would rather know how I can find out that something like this happens.
Later I put it between TryCatch but as expected it is not picked up.

So I thought I understood how Iterate_Rows until this happened.
The code is just before the part where reference is made to any childrows, which it never got around to...

 

So that's out of the world.
If you have any additional tips, I'd be more than happy to recommend them.

0 Likes
Message 10 of 13

Ralf_Krieg
Advisor
Advisor

Hello

 

Is strTotalQty a string or an integer? String will not work. Try CInt(strTotalQty)


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 11 of 13

checkcheck_master
Advocate
Advocate
Thanks Krieg, strTotalQty indeed is a string.
0 Likes
Message 12 of 13

maxim.teleguz
Advocate
Advocate

did you ever solve this?

0 Likes
Message 13 of 13

checkcheck_master
Advocate
Advocate

Hello Maxim,

You ask 'did you ever solve this?'.
Do you specifically mean using 'strTotalQty' and recommending making it 'CInt(strTotalQty)'?
About this: 'strTotalQty' is frequently used in the code but without the assignment of the variable type like 'integer/string' etc.
Or by 'this' do you mean the original problem statement as 'How can I get the Parent Document and the Parent Document Structure of a document?'?
Ultimately, I successfully wrote a tool that takes an assembly apart, divides it into categories, splits it out by material in separate material folders, saves to STEP, PDF, fills the title block with the required quantities in that specific assembly, etc.
Actually a fairly complete Production Output Tool, of course tailored to the needs of the company where I worked.
If the answer to your question is still missing, please be more specific about what you are looking for or what you are trying to achieve.
If I am able to help you, I would be happy to.
As you can see, I have also been helped enormously by Ralph Krieg, among others.