How to Get Model's Name on Drawing

How to Get Model's Name on Drawing

BeKirra
Advisor Advisor
1,670 Views
13 Replies
Message 1 of 14

How to Get Model's Name on Drawing

BeKirra
Advisor
Advisor

I find a function "Model Document Name" in "Advanced Drawing API" folder in the snippets browser.

IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

 

I also notice it works for the first document shown from its description.

"Get the name of first model document shown".

 

Supposed I inserted multiple models (IAM and IPT) in a drawing sheet.

My question is how to get the 2nd, 3rd, etc model's name by selecting its Drawing View on drawing?

 

Thanks for your help.

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Accepted solutions (1)
1,671 Views
13 Replies
Replies (13)
Message 2 of 14

chris
Advisor
Advisor

@BeKirra Can you show an example of what you are trying to do. I mean you can just add a view and then edit the view label and then add in the Part Number with the iProperties

chris_0-1726196374223.png

 

0 Likes
Message 3 of 14

BeKirra
Advisor
Advisor

Hi Chris,

Sorry, I should describe with more details.

Supposed I inserted the following components in the same drawing sheet.

Part 1.ipt

Part 2.ipt

Assembly 1.iam

 

In my case there is nothing to do with the drawing view names/tags (View Identifiers).

I want to grab the model file names then do something else (i.e. get the component's volume, weight) by using iLogic.

Can it be done? 😀

 

Hope this explains clearly.

 

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 4 of 14

Michael.Navara
Advisor
Advisor

You can use AllReferencedDocuments property of document

 

Sub Main()
    Dim referencedFileNames As New List(Of String)
    dim drw as DrawingDocument = ThisDoc.Document
    For Each refDoc As Document In drw.AllReferencedDocuments
        referencedFileNames.Add(refDoc.FullFileName)
    Next

    Logger.Debug(String.Join(vbCrLf,referencedFileNames))
End Sub

 

0 Likes
Message 5 of 14

chris
Advisor
Advisor

@BeKirra I'm interested in this workflow, please share whatever you figure out, this sounds like it would be very useful!

0 Likes
Message 6 of 14

BeKirra
Advisor
Advisor

Hi Chris,

No, I haven't figured out.

As mentioned earlier, I am wondering if I can add a text showing the individual part material or weight on drawing sheet.

I can manually add them to "View Identifier". However, it is not what I am looking for.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 7 of 14

WCrihfield
Mentor
Mentor

Hi @BeKirra.  Not sure if this is similar to what you want either, but here is a relatively simple iLogic rule that will first allow you to 'Pick' a drawing view, then gets the document the view is referencing, then gathers info (name, material, & mass) from it, then creates a new general note on the sheet containing that information.  For additional information, parts have a material, but assemblies do not.  Assemblies only contain other components, and those other components that represent parts have their own material.  The only exception is when it is a weldment type assembly, where we can specify the material to use for the weld beads, or when creating 'virtual' components, where we can specify what material the virtual component should be using.

Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
If oView Is Nothing Then Return
Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim sModelName, sMaterial, sMass As String
sModelName = System.IO.Path.GetFileName(oViewDoc.FullFileName)
If TypeOf oViewDoc Is PartDocument Then
	Dim oViewPDoc As PartDocument = oViewDoc
	sMaterial = oViewPDoc.ActiveMaterial.DisplayName
	sMass = oViewPDoc.ComponentDefinition.MassProperties.Mass.ToString
ElseIf TypeOf oViewDoc Is AssemblyDocument Then
	Dim oViewADoc As AssemblyDocument = oViewDoc
	sMass = oViewADoc.ComponentDefinition.MassProperties.Mass.ToString
End If
Dim oSheet As Sheet = oView.Parent
Dim oGNotes As GeneralNotes = oSheet.DrawingNotes.GeneralNotes
Dim oPos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim sFText As String = "Model Name = " & sModelName _
& vbCrLf & "Material = " & sMaterial _
& vbCrLf & "Mass = " & sMass
Dim oGNote As GeneralNote = oGNotes.AddFitted(oPos, sFText)

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 14

Curtis_Waguespack
Consultant
Consultant

@BeKirra wrote:

I find a function "Model Document Name" in "Advanced Drawing API" folder in the snippets browser.

IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

 


@BeKirra , in that same snippet folder are a couple of snippets that will allow you to work with any view to get the model that view references.

 

Hope that helps,

Curtis

 

Curtis_Waguespack_1-1726507472158.png

 

example:

Dim viewModelDoc = ActiveSheet.View("VIEW1").ModelDocument

'get the model name
sName = viewModelDoc.FullFileName
MsgBox(sName)

'set an iprop value in the model
viewModelDoc.PropertySets.Item("User Defined Properties").item("My iProp").Value = "Hello World"

 

EESignature

0 Likes
Message 9 of 14

chris
Advisor
Advisor

@WCrihfield What are the chances that if you got a few minutes that you could record a screen capture of walking through the above code you made and what it means and why you added what you did and where you found the stuff to add? Could it also include:

 

Model Part Number:

Model Description:

Solid Body Name:

Solid Body Mass (two decimal places)

 

and will it stay "live", that is if the solid body or part changes "mass" will the note automatically update?

0 Likes
Message 10 of 14

WCrihfield
Mentor
Mentor

Hi @BeKirra.

  • Could you provide an example of what you would like the resulting note to look like on your drawing sheet?
  • Should one note include names and information about all models represented on that sheet, or should there be a different note for each one of them?
  • Would it just be a regular general text note without any leader, a leader note, a table with columns for each piece of data, and rows for each directly referenced model on that sheet, or some other type of note?
    • Please explain in more detail.
  • Does the data shown within the note need to be 'live' or 'linked' to the model in some way, so that when the model changes, the data in the drawing will also automatically update?
    • If so, that will greatly complicate any code based solution needed to make that happen properly, if it is possible at all.
  • What version/year of Inventor are you currently using?
  • FYI:  The 'DisplayName' of the Material that a part is currently set to is not one of the properties that we can drop into a drawing note as linked information, but Mass is.  So, if we included the name of the material that a referenced part was using in a drawing note, it would be static information, instead of linked information.

 

Hi @chris.  I don't do screen recorded videos for posting online while at work.  I am already pushing the limits of my employer's grace by spending as much time as I currently do on the forums, helping others, when it was originally intended as research for improving our own automation solutions, which in turn is intended to improve productivity.  Plus, it includes privacy and security related issues / policies.  Plus typed text can easily be selected and translated, for those who do not speak English.

 

I can certainly 'get' those additional pieces of information by code, but no, it will not stay 'live' or 'linked' the way I was doing it in that example above.  As I'm sure you are aware, we can manually provide a link to the Part Number and Description iProperties within drawing notes, so we can also do that by code, but it is a lot more complicated to do it by code, because it must be done through the note's FormattedText property value, which is a String that includes lots of special XML tags, and special pointers to that very specific information, in that document.  However, body name and body mass are not available as pieces of information we can include a 'link' to manually within the Format Text dialog, so it can also not be included in a drawing note as 'linked' by code either, but it can be included as 'static' (will not update when the model changes) information.  I have created notes in drawings by code before that included information that was 'linked' to 'the model', but since drawing automation is not really my area of focus, I do not have a lot of experience creating notes like that by code, especially when they need to include multiple linked and non-linked pieces of information, formatted in specific ways, that would only be useful to someone else.  Besides the complexity the XML tags mentioned above, there can also be multiple other variables involved, that are either too complicated for me to type explanations for, or that I simply do not understand, that can make creating 'linked' notes by code even more complicated or unpredictable.  Some pieces of data that can be 'linked' are considered 'derived', because there is no normal parameter or property for them, so the information they are supposed to represent is extracted on-the-fly, so it can be shown in the note, in its place.  Those are specified by DerivedID numbers, instead of my their names, when creating them by code, with no Intellisense help to guide us about what is available, or possible.  And some can not be included in the same drawing note as any other linked data.

 

Usually, when someone wants to know how to create drawing notes that include 'linked' information in them, I point them to that online help documentation page linked to above, and I also tell them to 'reverse engineer' the note.  What I mean by reverse engineering the note is...create the note manually, using the very powerful, and helpful Format text dialog.  Then inspect the contents of that note's FormattedText property, to see how what they did manually changed its value.  Some of the stuff I see in some of those values seems a bit unpredictable, or simply undocumented, so there is not a good source of information or instructions on creating every possible variation of them by code.  There could likely be an entire university course on creating drawing notes with linked information in them, and it likely could not cover all possible pieces of information, in all possible scenarios.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 14

BeKirra
Advisor
Advisor

@WCrihfield wrote:

Hi @BeKirra.  Not sure if this is similar to what you want either, but here is a relatively simple iLogic rule that will first allow you to 'Pick' a drawing view, then gets the document the view is referencing, then gathers info (name, material, & mass) from it, then creates a new general note on the sheet containing that information.  For additional information, parts have a material, but assemblies do not.  Assemblies only contain other components, and those other components that represent parts have their own material.  The only exception is when it is a weldment type assembly, where we can specify the material to use for the weld beads, or when creating 'virtual' components, where we can specify what material the virtual component should be using.

 

Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
If oView Is Nothing Then Return
Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim sModelName, sMaterial, sMass As String
sModelName = System.IO.Path.GetFileName(oViewDoc.FullFileName)
If TypeOf oViewDoc Is PartDocument Then
	Dim oViewPDoc As PartDocument = oViewDoc
	sMaterial = oViewPDoc.ActiveMaterial.DisplayName
	sMass = oViewPDoc.ComponentDefinition.MassProperties.Mass.ToString
ElseIf TypeOf oViewDoc Is AssemblyDocument Then
	Dim oViewADoc As AssemblyDocument = oViewDoc
	sMass = oViewADoc.ComponentDefinition.MassProperties.Mass.ToString
End If
Dim oSheet As Sheet = oView.Parent
Dim oGNotes As GeneralNotes = oSheet.DrawingNotes.GeneralNotes
Dim oPos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim sFText As String = "Model Name = " & sModelName _
& vbCrLf & "Material = " & sMaterial _
& vbCrLf & "Mass = " & sMass
Dim oGNote As GeneralNote = oGNotes.AddFitted(oPos, sFText)

 

 


Hi Wesley,

Your code is what I am after.

Can the mass be shown as kilogram with no decimal?

It'd be great.

 

And yes, it's pity there is no material info in assembly.

 

Thanks a lot. 😀 

 

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 12 of 14

BeKirra
Advisor
Advisor

@WCrihfield wrote:

Hi @BeKirra.

  • Could you provide an example of what you would like the resulting note to look like on your drawing sheet?
  • Should one note include names and information about all models represented on that sheet, or should there be a different note for each one of them?
  • Would it just be a regular general text note without any leader, a leader note, a table with columns for each piece of data, and rows for each directly referenced model on that sheet, or some other type of note?
    • Please explain in more detail.
  • Does the data shown within the note need to be 'live' or 'linked' to the model in some way, so that when the model changes, the data in the drawing will also automatically update?
    • If so, that will greatly complicate any code based solution needed to make that happen properly, if it is possible at all.
  • What version/year of Inventor are you currently using?
  • FYI:  The 'DisplayName' of the Material that a part is currently set to is not one of the properties that we can drop into a drawing note as linked information, but Mass is.  So, if we included the name of the material that a referenced part was using in a drawing note, it would be static information, instead of linked information.

 

Hi Wesley,

Your code meets what I need as mentioned in my last reply.

  • Regular note works for my situation.
  • An option of continuously selecting drawing views would be nice. I need to insert the note with each drawing view when multiple components showing on the same sheet. In most of the cases the note will be attached to each drawing view.
  • Can the model name be shown without model's format (.IPT, .IAM)?
  • It'd be great if the data can be updated automatically when the IPT and IAM are updated.
  • Can an "IF" statement be added to the code so the line of material won't be shown in the note when the model is an IAM?
  • Can the note be located just below the selected view rather than in the lower left corner in the sheet?
  • I am with Inventor 2023

Appreciated for your time.

Thanks again. 😀

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 13 of 14

WCrihfield
Mentor
Mentor
Accepted solution

Hi @BeKirra.  Here is an updated version of the code I posted earlier, with most of those changes.  However, this code will only gather current information and put it in a new note.  It does not create a new note that contains 'links' to that information from within the view's model that would automatically update itself as the model changes.  It might be possible to create a note like that, but you would have to get the model name from a different source, such as maybe Part Number or something like that, and including the links would require a longer and much more complex code.

Dim eFilter As SelectionFilterEnum = SelectionFilterEnum.kDrawingViewFilter
Dim sPrompt As String = "Select a Drawing View - or press ESC key to exit."
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
PickAgain:
	Dim oView As DrawingView = Nothing
	oView = ThisApplication.CommandManager.Pick(eFilter, sPrompt)
	If oView Is Nothing Then Return
	Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim sModelName, sMaterial, sMass As String
	sModelName = System.IO.Path.GetFileNameWithoutExtension(oViewDoc.FullFileName)
	If TypeOf oViewDoc Is PartDocument Then
		Dim oViewPDoc As PartDocument = oViewDoc
		sMaterial = oViewPDoc.ActiveMaterial.DisplayName
		sMass = Round(oViewPDoc.ComponentDefinition.MassProperties.Mass, 0).ToString & " kg"
	ElseIf TypeOf oViewDoc Is AssemblyDocument Then
		Dim oViewADoc As AssemblyDocument = oViewDoc
		sMass = Round(oViewADoc.ComponentDefinition.MassProperties.Mass, 0).ToString & " kg"
	End If
	Dim oSheet As Sheet = oView.Parent
	Dim oGNotes As GeneralNotes = oSheet.DrawingNotes.GeneralNotes
	'point below center of view
	Dim oPos As Point2d = oTG.CreatePoint2d(oView.Left + (oView.Width / 2), (oView.Top - oView.Height) -.5)
	Dim sFText As String = "Model Name = " & sModelName
	If sMaterial IsNot Nothing AndAlso sMaterial <> "" Then
		sFText &= vbCrLf & "Material = " & sMaterial
	End If
	sFText &=  vbCrLf & "Mass = " & sMass
	Dim oGNote As GeneralNote = oGNotes.AddFitted(oPos, sFText)
GoTo PickAgain

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 14

BeKirra
Advisor
Advisor

Thanks to @WCrihfield 

😀

I think I can learn something from your code.

 

Also thanks to other peoples' inputs.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes