add text to bottom left of of base view when added to sheet

add text to bottom left of of base view when added to sheet

NachoShaw
Advisor Advisor
890 Views
9 Replies
Message 1 of 10

add text to bottom left of of base view when added to sheet

NachoShaw
Advisor
Advisor

Hi

 

basically as the title suggests. I am adding a base view to a drawing sheet automatically. what i need to do is add some text to the bottom left of that view with the display name of the file. I need to have the text justified bottom left (this point to align with the bottom left of the view) and the text needs to be about 50mm in height.

 

How can i add text during or immediately after the base view is added?

can i manually control the format of the text i.e. height, font, color, justification?

 

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
891 Views
9 Replies
Replies (9)
Message 2 of 10

HideoYamada
Advisor
Advisor

Hello NachoUK,

 


@NachoShaw wrote:

I am adding a base view to a drawing sheet automatically.

 

How can i add text during or immediately after the base view is added?


 If your macro/addin adds base view, why don't you do it at the end of the macro/addin?

There will be a reason why, please let us know.

Or do you just want to know how to add the text to the drawing?

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 10

NachoShaw
Advisor
Advisor

hey

just needed to know how to add the text. i found a sample of Brians that adds a leader then deletes it which is ok but i cant seem to control the justification, i can override the text but thats it

 

thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 4 of 10

Sergio.D.Suárez
Mentor
Mentor

Hi, I think it could be useful to work with the view label. Then if you move your eyes the text will move with it.
Try the following code. Place the name of the file with a specific font.
I hope I can be useful and help you develop your code. Regards

 

Dim sFont As String =  "ISOCPEUR"  ' "ISOCP_IV25"
Dim sFSize1 As Double = 0.5 'font size in cm 

Dim oDoc As DrawingDocument = ThisDoc.Document

Dim refDoc As Document 
	
For Each oSheet In oDoc.Sheets
	For Each oView As DrawingView In oSheet.DrawingViews
		oView.ShowLabel = True
		
		refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oView.Label.Position = ThisApplication.TransientGeometry.CreatePoint2d(oView.Left-1, oView.Top-oView.Height-1)
		
		oView.Label.FormattedText =  "<StyleOverride Font='" & sFont & "' FontSize='" & sFSize1 & "' Bold='True'>"& refDoc.DisplayName &"</StyleOverride>"
		oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
	Next
Next
	

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 10

NachoShaw
Advisor
Advisor

Hi

 

I originally didnt want to use the label as its set up for different use but i didnt consider overriding the style of that. i will try later tonight, thats for that 🙂

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 6 of 10

HideoYamada
Advisor
Advisor

Hello,

 

Now we are talking about how to add General Notes here :

https://forums.autodesk.com/t5/inventor-customization/general-notes-formatted-text-linked-parameter-...

 

Is this helping you?

 

~~~

By the way, there are several places to added text.

(1) Sheet.

(2) Sketch associated with the Sheet.

(3) Sketch associated with the DrawingView.

I usually use the 3rd place because the texts will follow if the view has moved.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 7 of 10

lmc.engineering
Advocate
Advocate

Hi @NachoShaw 

 

This should do most of what you are after:

Public Sub Main()
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	'Get View object
	Dim viewNo As Integer = 1
	Dim refView As DrawingView = oDoc.ActiveSheet.DrawingViews(viewNo)	
	'Get file reference of view object
	Dim oRefFileDesc As ReferencedFileDescriptor = refView.ReferencedFile
	Dim oAssyDoc As Document = oRefFileDesc.ReferencedDocument
	'Set text string
	Dim myText As String = 	oAssyDoc.DisplayName
    'Get coordinates of text
	Dim dimCoords As String() = GetViewCoords(refView, "BottomLeft")	
	'set ref to transient geometry
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry	
	'Set reference to active sheet
	Dim oActiveSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
	' Set a reference to the GeneralNotes object
    Dim oGeneralNotes As GeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes
	'Create text
	sFormattedText="<StyleOverride Font='Arial' FontSize='0.5' Bold='True' Italic='True' Underline='False'>" & myText & "</StyleOverride>" 
	oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(dimCoords(0), dimCoords(1)), sFormattedText)	
End Sub
	
	Private Function GetViewCoords(refView As DrawingView, Justification As String) As String()
		Dim dimCtrX As Double = refView.Center.X
		Dim dimCtrY As Double = refView.Center.Y
		Dim viewWidth As Double = refView.Width
		Dim viewHeight As Double = refView.Height		
		Dim textX As Double 
		Dim textY As Double	
		
		Select Case Justification
		Case "BottomLeft"
		'Bottom left justification
		textX = dimCtrX - (viewWidth / 2)
		textY = dimCtrY - (viewHeight / 2)
		Case "BottomRight"
		'Bottom right justification
		textX = dimCtrX + (viewWidth / 2)
		textY = dimCtrY - (viewHeight / 2)
		Case "TopLeft"
		'Top left justification
		textX = dimCtrX - (viewWidth / 2)
		textY = dimCtrY + (viewHeight / 2)
		Case "TopRight"
		'Top right justification
		textX = dimCtrX + (viewWidth / 2)
		textY = dimCtrY + (viewHeight / 2)
		End Select
		
		Dim s As String()
		s = {textX,textY}		
		Return s
    End Function

 

the only thing I cannot change is the text colour as there is no XML <styleOverride> for this.  I believe you will need to create a layer and move the Generalnote object to that layer in order to set the colour.

 

Cheers

0 Likes
Message 8 of 10

NachoShaw
Advisor
Advisor

Hi

 

I have been working through your suggestion. Im looking at going with this as i can add in Property values in the StyleOverrride which is helpful. However, i cannot get it stay justified left. even though the text is JL, the label itself seems to be always positioned from the center. Is there a way of forcing the text to stay justified / aligned with the left of the view?

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 9 of 10

NachoShaw
Advisor
Advisor

Hey

 

i have this working ok now but wondered if there was an easier way to add the iproperty values into the Style override?

Here is my current code

 

oView.Position = objPoint2D
        objPoint2D = Nothing
        oView.ShowLabel = True

        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
        oView.Label.FormattedText = "<StyleOverride " &
                                    "Font='Arial' " &
                                    "FontSize='1' " &
                                    "Bold='True'>" &
                                    "Job No. = " & txtJobNo.Text &
                                    "<Br/>Part No. = " & sPN &
                                    "<Br/>Description = " & sName &
                                    "<Br/>Qty = " & sQty &
                                    "<Br/>BOM Item = " & sItem &
                                    "<Br/>Material = " & sMat &
                                    "</StyleOverride>"

as you can see, the values for Part No, Description, Qty, BOM Item & Material are entered into the formatted text as hard text collected from a part in a loop which is OK but if anything changes, i need to run the code again. It would be so much better if it could read the properties

 

I found this in the help file

 

The example below will display the string associated with the description property of the design tracking properties associated with the document containing the model referenced by the first view on the sheet. The backslash at the end of the tag definition denotes that the opening and closing tags have been combined. This is useful in this case since a property tag does not require any additional information besides what’s provided by the attributes.

<Property Document="model" FormatID="{32853F0F-3444-11d1-9E93-0060B03C1CA6}" PropertyID="29" />

 

I did find a list of Property ID's here https://forums.autodesk.com/t5/inventor-customization/get-set-iproperty-directly-with-id-enum/td-p/5...

 

im going to try this

oView.Label.FormattedText = 
"<StyleOverride Font='Arial' FontSize='1' Bold='True'>" &
"Job No. = " & txtJobNo.Text &
"<Br/>Part No. = <Property Document="model" FormatID="{32853F0F-3444-11d1-9E93-0060B03C1CA6}" PropertyID="5" />" &
"<Br/>Description = <Property Document="model" FormatID="{32853F0F-3444-11d1-9E93-0060B03C1CA6}" PropertyID="29" />" &
"<Br/>Qty = " & sQty & "<Br/>BOM Item = " & sItem & "<Br/>Material = <Property Document="model" FormatID="{32853F0F-3444-11d1-9E93-0060B03C1CA6}" PropertyID="20" />" &
"</StyleOverride>"

Any pointers?

 

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 10 of 10

NachoShaw
Advisor
Advisor

so it works ok, as a note, you will need to double quote anything in a set of quotes

 

"model" = ""model""

 oView.Label.FormattedText = "<StyleOverride " &
                                    "Font='Arial' " &
                                    "FontSize='1' " &
                                    "Bold='True'>" &
                                    "Job No. = " & txtJobNo.Text &
                                    "<Br/>Part No. = <Property Document=""model"" FormatID=""{32853F0F-3444-11d1-9E93-0060B03C1CA6}"" PropertyID=""5"" />" &
                                    "<Br/>Description = <Property Document=""model"" FormatID=""{32853F0F-3444-11d1-9E93-0060B03C1CA6}"" PropertyID=""29"" />" &
                                    "<Br/>Qty = " & sQty &
                                    "<Br/>BOM Item = " & sItem &
                                    "<Br/>Material = <Property Document=""model"" FormatID=""{32853F0F-3444-11d1-9E93-0060B03C1CA6}"" PropertyID=""20"" />" &
                                    "</StyleOverride>"

properties.png

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes