iLogic Add text under dimension

iLogic Add text under dimension

jishee
Enthusiast Enthusiast
3,297 Views
15 Replies
Message 1 of 16

iLogic Add text under dimension

jishee
Enthusiast
Enthusiast

I have code that will add test under a dimension for the first dimension. How do I modify the code to add the text under all dimensions of a certain dimension style?

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet =  ActiveSheet.Sheet
'reference to some dimension
Dim oDim As GeneralDimension = oSheet.DrawingDimensions.Item(1)
'refrence to the DimensionText object
Dim oDimensionText As DimensionText = oDim.Text
'Change dimension text
oDimensionText.FormattedText = "<DimensionValue/><br/>DLO"

 

0 Likes
Accepted solutions (1)
3,298 Views
15 Replies
Replies (15)
Message 2 of 16

ianteneth
Advocate
Advocate

Hi @jishee,

 

Here is some code that will add the text "DLO" to each dimension in a drawing. You said you only want it to run for a certain "style" of dimension. What do you mean by "style" (Oridinate, baseline, or the style in the image below?

 

Annotation 2020-05-01 094816.png

 

 

' Get the currently active file.
Dim document As Document = ThisApplication.ActiveDocument
' Get text that is added to the dimensions.
Dim EXTRA_DIMENSION_TEXT As String = "DLO"

' Check if open file is a drawing.
If document.SubType = "{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
	' Get currently active file as a drawing.
	Dim drawing As DrawingDocument = document
	
	' Loop through every dimension in the active sheet in the drawing.
	For Each dimension As GeneralDimension In drawing.ActiveSheet.DrawingDimensions
		' Update the dimension text.
		dimension.Text.FormattedText = "<DimensionValue/><br/>" & EXTRA_DIMENSION_TEXT
	Next dimension
	
End If

 

Annotation 2020-05-01 100330.png

 

Message 3 of 16

jishee
Enthusiast
Enthusiast

Hi @ianteneth 

 

I have two custom dimension styles in my drawing and I only want the "DLO" test to be added to one of the styles.

0 Likes
Message 4 of 16

ianteneth
Advocate
Advocate

So the styles from the picture in my last post? What is the name of the style?

0 Likes
Message 5 of 16

jishee
Enthusiast
Enthusiast

Style name is "WW Dimension DLO"

0 Likes
Message 6 of 16

WCrihfield
Mentor
Mentor

Give this a try:

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = ActiveSheet.Sheet
For Each oDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
	oDim.Text.FormattedText = "<DimensionValue/><br/>DLO"
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 16

WCrihfield
Mentor
Mentor
Accepted solution

Sorry, I hadn't updated the page in a while, or I would have seen all the previous replies.

Try this instead.

 

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = ActiveSheet.Sheet
For Each oDim As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions
			If oDim.Style Is oDoc.StylesManager.DimensionStyles.Item("WW Dimension DLO") Then
				oDim.Text.FormattedText = "<DimensionValue/><br/>DLO"
			End If
		Next
	End If
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 16

jishee
Enthusiast
Enthusiast

Worked perfectly. Thank you for the help!!

0 Likes
Message 9 of 16

Anonymous
Not applicable

Hi,

 

Unrelated to this topic 😐 sorry. 

 

I am trying to create an ilogic code for symmetric tolerances  and I have come across an existing code. However I want to add if  conditions to this code like if dimension is 0-400 then tolerance is 1 else 2 etc... 

 

I tried to add if logic, but I am getting an error cannot be converted to boolean. How can I solve this error?

 

Regards

Venkat

 

'symmetric example
' Set a reference to the select set of the active document. Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument ' Find all selected occurrences and add them to an ObjectCollection. Dim oDrawingDims As DrawingDimension 'Loop through all dimensions For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions 'set Tolerance Method oDrawingDims.Tolerance.SetToSymmetric( 0.5) Next

 

 

0 Likes
Message 10 of 16

Anonymous
Not applicable

Hi,

 

I am able to add a position number to each drawing dimension using your code, however it's a fixed text to each dimension (please have a look at attachment: Position_number). But I want to add a different position number for each dimension, like in position_number-1 attachment. Please help me. 

0 Likes
Message 11 of 16

WCrihfield
Mentor
Mentor

Hi @Anonymous.  Here is some iLogic rule code that should get you pretty close to your goal.  The biggest hurtle within this code left for you to deal with is the raw numbers.  In iLogic, any raw numbers that are representing measurements are understood by Inventor as 'database' units.  This means length interpreted in centimeters, angles in radians, mass in grams, etc.  So if your raw numbers need to represent other units than those you will likely have to change your raw numbers, one way or another, to get Inventor to understand it the way you want.

I use Inches, so in my test runs of this rule, I had to specify the lower tolerance as 2.54 to get it to come out as 1 in the drawing, and 5.08 for the higher tolerance, to get it to come out as 2 in the drawing.  So you may need to change those numbers to suit your preferred units.  I also threw in some code for a 'Transaction', to help bundle all those actions done by the rule into one item in the 'UNDO' list, to help in cleanup if the rule doesn't do exactly what you want.

Here is the rule:

Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument

'This combines all following actions into a single entry in the 'Undo' list.
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "iLogic - Edit All Dims")

Dim oGDims As GeneralDimensions = oDDoc.ActiveSheet.DrawingDimensions.GeneralDimensions
Dim oInt As Integer = 1
For Each oGDim As GeneralDimension In oGDims
	Try
		If oGDim.ModelValue <= 400 Then
			oGDim.Tolerance.SetToSymmetric(2.54)
		ElseIf oGDim.ModelValue > 400 Then
			oGDim.Tolerance.SetToSymmetric(5.08)
		End If
		'eliminate any decimal points in the tolerance numbers
		oGDim.TolerancePrecision = 0
		oGDim.Text.FormattedText = "Pos " & oInt & " - <DimensionValue/>"
		oInt = oInt + 1
	Catch oEx As Exception
		MsgBox(oEx.Message & vbCrLf & oEx.StackTrace,,"")
	End Try
Next
oTrans.End

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 12 of 16

Anonymous
Not applicable

Hi @WCrihfield 

Thank you so much. The position number part is working perfectly. However, tolerance values are not updating. It's adding tolerance '1' to every dimension. 

 

Please have a look at the code below. My dimensions are in mm so changed the tolerances as you mentioned but still no luck.  

Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument

'This combines all following actions into a single entry in the 'Undo' list.
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "iLogic - Edit All Dims")

Dim oGDims As GeneralDimensions = oDDoc.ActiveSheet.DrawingDimensions.GeneralDimensions
Dim oInt As Integer = 1
For Each oGDim As GeneralDimension In oGDims
	Try
		If oGDim.ModelValue <= 400 Then
			oGDim.Tolerance.SetToSymmetric(0.1)
		ElseIf oGDim.ModelValue > 400 And oGDim.ModelValue <= 1000 Then
			oGDim.Tolerance.SetToSymmetric(0.2)
			ElseIf oGDim.ModelValue > 1000 And oGDim.ModelValue <= 2000 Then
			oGDim.Tolerance.SetToSymmetric(0.3)
			ElseIf oGDim.ModelValue > 2000 And oGDim.ModelValue <= 4000 Then
			oGDim.Tolerance.SetToSymmetric(0.4)
			End If
		'eliminate any decimal points in the tolerance numbers
		oGDim.TolerancePrecision = 0
		oGDim.Text.FormattedText = "Pos " & oInt & " - <DimensionValue/>"
		oInt = oInt + 1
	Catch oEx As Exception
		MsgBox(oEx.Message & vbCrLf & oEx.StackTrace,,"")
	End Try
Next
oTrans.End

 

0 Likes
Message 13 of 16

Anonymous
Not applicable

Hi,

 

I solved it by adapting all the values to mm  🙂 

0 Likes
Message 14 of 16

gatuma
Explorer
Explorer

Hi everyone!

 

I've been busting my head for too long and now I hope one of you would be so kind and help me out. I tried adjusting the code provided in some of the previous responses here and also dabbled with the Inventor-provided snippets but I just can't find a proper way to make it work.

 

I wrote some code, that adds dimensions to a model. However this model is parametric and it will change quite drastically with each new iteration, so naturally, the dimensions will also change - some new dimensions will be included, some excluded.

I want iLogic to add text to each dimension. But, as mentioned, the dimensions change with each new drawing copy and each dimension requires different text, so I need my code to find the right dimension based on the dimension name (or if anyone knows a better way).

For example, one dimension is namend "AADim1". How can I find this specific dimension and make it so that it will read: "AA <DimensionValue/>" ? 

Then for the next example, I have the dimension "frameDim1", and I would like the dimension text in this specific dimension to read: "Frame <DimensionValue/>. I'll have many more example to add in the future.

 

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Blatt:1")

Dim a1 As Double = 0.5
Dim b1 As Double = 1.8 'rahmen
Dim b2 As Double = 1.6 'AA
Dim b3 As Double = 1.4 'seitenwand

Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim VIEW2 = Sheet_1.DrawingViews.ItemByName("VIEW2")
Dim VIEW3 = Sheet_1.DrawingViews.ItemByName("VIEW3")

Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions

ThisDrawing.BeginManage()
	'VIEW1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Dim rearSeitenwand = VIEW1.GetIntent(framePart, "rearSeitenwand")
	Dim rueckwandFace = VIEW1.GetIntent(framePart, "rueckwandFace")
	Dim frontSeitenwand = VIEW1.GetIntent(framePart, "frontSeitenwand")
	Dim rearBandrahmen = VIEW1.GetIntent(framePart, "rearBandrahmen")
	Dim frontBandrahmen = VIEW1.GetIntent(framePart, "frontBandrahmen")
	Dim rearAxle = VIEW1.GetIntent(framePart, "rearAxle")
	Dim frontAxle = VIEW1.GetIntent(framePart, "frontAxle")
	
	If Not Direction = "REV" Then
		Dim rueckwandDim1 = genDims.AddLinear("rueckwandDim1", VIEW1.SheetPoint(a1, b3), rearBandrahmen, rueckwandFace)
		Dim seitenwandDim1 = genDims.AddLinear("seitenwandDim1", VIEW1.SheetPoint(a1, b3), rearSeitenwand, frontSeitenwand)
	End If
	
	Dim frameDim1 = genDims.AddLinear("frameDim1", VIEW1.SheetPoint(a1, b1), rearBandrahmen, frontBandrahmen)
	Dim AADim1 = genDims.AddLinear("AADim1", VIEW1.SheetPoint(a1, b2), rearAxle, frontAxle)

	'VIEW3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Dim frameRight = VIEW3.GetIntent(framePart, "frameRight")
	Dim frameLeft = VIEW3.GetIntent(framePart, "frameLeft")
	
	
	
	
	'***************************************************************************
	'Add text to dimensions
		
		
	
	
		
	'***************************************************************************

ThisDrawing.EndManage()

 

0 Likes
Message 15 of 16

WCrihfield
Mentor
Mentor

Hi @gatuma.  When you create the dimensions using those iLogic snippet codes such as IManagedGeneralDimensions.AddLinear, they allow you to specify a name for the dimension as you create it.  So, if you want to get that same dimension again later by its name, you can use the IManagedGeneralDimensions.ItemByName property, then specify its name within the () area.  If the dimension you specify can be found, it will return that dimension, otherwise if it can not be found, it will throw an error.  As for how to change the text within the dimension...that is often more complicated.  You will need to get the 'native' object (a real GeneralDimension Inventor API object, or one of its more specific derived types), instead of the IManagedGeneralDimension type object.  The real GeneralDimension type object will have many methods & properties you can access.  The property you will want to focus on is its Text property, which will return a DimensionText type object.  Then that DimensionText object has two different similar properties (Text & FormattedText).  If the text in your dimension is just simple, static text, with no special formatting, and not 'linked' to anything, then you can likely just use the Text property to do what you want.  However, if the text you have in the dimension needs to maintain any special formatting, or needs to remain 'linked' to something, then you will most likely need to deal with the FormattedText property.  When dealing with the FormattedText property, its value will most likely contain some XML tags, which can make the task pretty confusing, if you are not familiar with them and how they work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 16 of 16

gatuma
Explorer
Explorer

@WCrihfield 

Sorry for the late reply, I just haven't gotten aroud to trying to fix this issue. But taking your comment into consideration and with a little trial&error testing, I was able to make it work, so Thank you for your input.

0 Likes