Retrieve part name within drawing

Retrieve part name within drawing

DavidTunnard
Collaborator Collaborator
1,309 Views
4 Replies
Message 1 of 5

Retrieve part name within drawing

DavidTunnard
Collaborator
Collaborator

Hello,

 

Is there a way I can call up the file name of the part used in the drawing? I think that is what I want anyway!

 

Desired outcome if interested:

I want to create a rule that automatically updates the mass of the part when I either save or export a drawing. This will hopefully update the linked MASS field in my notes so that it doesn't read N/A all the time.

0 Likes
Accepted solutions (1)
1,310 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

There are multiple ways to get access to the 'model' document being represented within a drawing document.  If you are using a 'local' (saved within the document) iLogic rule, you can use this route:

 

ThisDrawing.ModelDocument

 

The following two references can be used in either a local or external rule (where you've already defined the oDDoc variable as the 'active' drawing document.):

The following line assumes that the first drawing view in your drawing is representing the model document you are targeting.

 

oDDoc.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

 

This next line simply assumes that the first document being referenced by your drawing is the model document.

 

oDDoc.ReferencedDocuments.Item(1)

 

 After you have reached that document, you may have to assign the generic document object as the value of a PartDocument type Variable, so that you can access its PartComponentDefinition.  The MassProperties are located under that component definition.

 

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)

0 Likes
Message 3 of 5

DavidTunnard
Collaborator
Collaborator

Thank you. I am still very new to using ilogic.  I don not understand what you mean by this part

 

" After you have reached that document, you may have to assign the generic document object as the value of a PartDocument type Variable, so that you can access its PartComponentDefinition."

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

I was attempting to help you achieve your second goal of working with the Mass of the part document.  Only assembly documents and part documents have mass, so in order to get to that mass, you have to create a PardDocument type of variable, then set the 'model document' you retried through the lines of code above as the value of this new variable, so that this new variable will be representing that part document.  Once you have done this, you will then have access to all the stuff (properties, objects within, functionality) specific to that part document, through this new variable.

'create a variable for a drawing document, then set its value
Dim oDDoc As DrawingDocument = ThisDrawing.Document
'that variable now represents our local drawing document

'check if the model document this drawing is representing is a Part (specificly)
If ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	'it is, so create a Part specific document variable, then set its value
	Dim oPDoc As PartDocument = ThisDrawing.ModelDocument
	'that variable now represents that part document
	
	'create a String (text) type variable, to hold the part's name, then set its value
	Dim oName As String = oPDoc.FullFileName
	'that variable now represents that text
	
	'create a Double (number with decimal places) type variable, then set its value
	'had to climb down through the object structure under that Part to get it
	Dim oMass As Double = oPDoc.ComponentDefinition.MassProperties.Mass
	'that variable now represents the Mass of the part
	
	'show the user (you) a message containing the data we collected about the part.
	MsgBox("Model name = " & oName & vbCrLf & _
	"Model Mass = " & oMass, , "")
End If

 

In iLogic, everything is structured by objects.  Documents are one of the objects that are high in the structure.  Each object may have a certain set of properties (data, settings, other objects), methods (actions you can do with/to this object), and events (notifications of when stuff happens to this object).  There are multiple types of document objects.  There is a generic document object which doesn't represent any specific type of Inventor document, and has fewer stuff available to it, then there are the other types of document objects, which represent one specific type of Inventor document only, and will provide access to lots of stuff specific to that type of Inventor document.  In your case you are trying to access a Part document, so in order to access part specific stuff and functionality, iLogic needs to understand the document object as that specific type of document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

DavidTunnard
Collaborator
Collaborator

Thank you very much.

 

Just trying to get my head around your rule. This is how I interpret it.

 

'create a variable for a drawing document, then set its value
Dim oDDoc As DrawingDocument = ThisDrawing.Document
'that variable now represents our local drawing document

This is an instruction to look at the current open drawning.

 

'check if the model document this drawing is representing is a Part (specificly)
If ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	'it is, so create a Part specific document variable, then set its value
	Dim oPDoc As PartDocument = ThisDrawing.ModelDocument
	'that variable now represents that part document

 Checking to see if the model is a part/assembly. If it is then get the model name.

 

	'create a String (text) type variable, to hold the part's name, then set its value
	Dim oName As String = oPDoc.FullFileName
	'that variable now represents that text

This is to get the full file name of the model.

 

'create a Double (number with decimal places) type variable, then set its value
	'had to climb down through the object structure under that Part to get it
	Dim oMass As Double = oPDoc.ComponentDefinition.MassProperties.Mass
	'that variable now represents the Mass of the part

This is getting the mass from the full file name

 

	'show the user (you) a message containing the data we collected about the part.
	MsgBox("Model name = " & oName & vbCrLf & _
	"Model Mass = " & oMass, , "")

This is putting that information together and showing it in a message box. However, I am not sure how this is working? i.e where are you getting  "model name = " & oName & vbCrLf & _" From?

 

I just searched vbCrlf and realised it's just a line return. I think I understand what that last bit is doing now.

0 Likes