Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Naming individual dimensions in drawing

5 REPLIES 5
Reply
Message 1 of 6
op_thorsager
619 Views, 5 Replies

Naming individual dimensions in drawing

Hi, i've heard that its possible to name drawing dimensions by using inspection dimensions. the workflow supposedly is as follows: *enable* inspection dimension on the dim you want to name -> set label -> *disable* inspection dimension (label will still be visible to inventor, as it doesn't delete the label value.

 

op_thorsager_0-1675416241644.png

in above picture i want to write an ilogic rule which will delete the dimension named "600" if the value after x is "0"

i have given the said dimension an inspection label called "del", then disabled inspection dimension. 

 

all of the other dimensions should still be in the drawing. How would the approach to this be? i can't seem to find anything online except for rules which delete all dimensions, which i don't want.

 

been looking through the inventor api list by autodesk, but cant seem to find any forms which will be able to specify dimensions based on inspection label 

5 REPLIES 5
Message 2 of 6
tyler.warner
in reply to: op_thorsager

@op_thorsager this is a cool idea & will be helpful for me in a current project, thanks for sharing! The inspection dimension data is inaccessible unless the dimension is currently an inspection dimension. The below rule goes through all of the dimensions on the current sheet, makes it an inspection dimension, checks if its label is "del", deletes it if so & then resets it back to not an inspection dimension.

Dim oDrawingDocument As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawingDocument.ActiveSheet
Dim oDrawingDims As DrawingDimensions = oSheet.DrawingDimensions
Dim oLabel As String
Dim oRate As String

For Each oDrawingDim As DrawingDimension In oDrawingDims	
	Try
		oDrawingDim.IsInspectionDimension = True
		oDrawingDim.GetInspectionDimensionData(kNoInspectionBorder, oLabel, oRate)
		If oLabel = "del" Then
			oDrawingDim.Delete
		End If
	Catch
	End Try
	
	Try
 		oDrawingDim.IsInspectionDimension = False
	Catch
	End Try
Next
If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
Message 3 of 6
WCrihfield
in reply to: op_thorsager

Hi @op_thorsager@tyler.warner.  Just dropping in a good tool I created a while back for assigning names to stuff in Inventor that you want to be able to find again easily.  It works similarly to the 'NamedEntities' interface, but does not use the same naming conventions.  There is a custom Sub routine for taking care of the technical stuff (main task), but it is best to specify as much as possible, as preparation, within the Sub Main area.  I made it fairly flexible, by having extra lines of code in there, but leaving them commented out, just as ideas for different ways to use the tool.  As it is right now, it is customized for letting you 'Pick' a DrawingDimension, then asks you to enter a name for it.  The AttributeSet name and Attribute name have already been specified, specifically for dimensions, but you can either change those values, or use the InputBox options.  This is all within a loop that will run as many times as you want it to.  The loop will break/exit when either you do not select anything, or you do not enter a name, so it will not be an endless loop.  As you can see, if you choose to not supply values for the AttributeSet name or the Attribute name, it will attempt to create values to use for you.  However, those names are driven by the selected object's Type name, which may be a lot more specific than you have in mind...such as "Named_RadiusGeneralDimension" for the set, and "RadiusGeneralDimension_Name" for the attribute, if that is the Type of object you selected.

Here is the code:

Sub Main
	Dim DimName, SetName, AttName As String
	'SetName = InputBox("Enter AttributeSet Name", "AttributeSet Name", SetName)
	'If SetName = "" Then Exit Sub
	SetName = "Named_Dimensions"
	'AttName = InputBox("Enter Attribute Name", "Attribute Name", AttName)
	'If AttName = "" Then Exit Sub
	AttName = "Dimension_Name"
	'Dim oInt As Integer = 0 'could use this in naming routine, within loop
	PickAgain :
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select A Dimension To Assign A Name To.")
	If IsNothing(oObj) OrElse TypeOf oObj Is DrawingDimension = False Then Exit Sub
	Dim oDDim As DrawingDimension = oObj
	DimName = InputBox("Enter Dimension Name", "Dimension Name", DimName)
	If DimName = "" Then Exit Sub
	AssignName(oDDim, DimName, SetName, AttName)
'	AssignName(oDDim, DimName)
	GoTo PickAgain 'will exit if nothing is 'Picked', or no Name entered
End Sub

Sub AssignName(ToName As Object, Name As String, _
Optional SetName As String = vbNullString, Optional AttName As String = vbNullString)
	If IsNothing(ToName) Or Name = "" Then Exit Sub
	Dim sType As String = TypeName(ToName)
	If String.IsNullOrEmpty(SetName) Then SetName = "Named_" & sType & "s"
	If String.IsNullOrEmpty(AttName) Then AttName = sType & "_Name"
	'MsgBox("SetName = " & SetName & vbCrLf & "AttName = " & AttName,,"")
	
	Dim oSets As AttributeSets = Nothing : oSets = ToName.AttributeSets
	Dim oSet As AttributeSet = Nothing
	If oSets.NameIsUsed(SetName) Then
		oSet = oSets.Item(SetName)
	Else : oSet = oSets.Add(SetName) : End If
	
	Dim oAtt As Attribute = Nothing
	If oSet.NameIsUsed(AttName) Then
		oAtt = oSet.Item(AttName)
		If oAtt.Value <> Name Then
			oAns = MsgBox("That " & sType & "already has a different name assigned to it." & vbCrLf & _
			"Do you want to change its name [Yes] or leave it alone [No]?", vbYesNo + vbQuestion, sType & " Has Other Name")
			If oAns = vbYes Then oAtt.Value = Name
		End If
	Else : oAtt = oSet.Add(AttName, ValueTypeEnum.kStringType, Name) : End If
End Sub

Of course, there are also a few Inventor add-ins out there for similar purposes that may work just as good, such as Nifty Attributes.

 

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 4 of 6

Here is another way to do this using the iLogic functions.

 

First we create a dimension with a rule, and name it:

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim oView_1 = Sheet_1.DrawingViews.ItemByName("View1")

Dim XY_Plane = oView_1.GetIntent("XY Plane")
Dim Top_Plane = oView_1.GetIntent("Top Plane")

Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
genDims.AddLinear("Carl The Drawing Dimension", oView_1.SheetPoint(1.5 * 1, 0), XY_Plane, Top_Plane)

 

And then later you can access the dimension by name with a rule such as this:

 

Dim oiLogicDims = ThisDrawing.Sheets.ItemByName("Sheet:1").DrawingDimensions.GeneralDimensions

Dim oDrawingDim As DrawingDimension
oDrawingDim = oiLogicDims.ItemByName("Carl The Drawing Dimension").NativeEntity

oDrawingDim.Delete

 

Message 5 of 6
op_thorsager
in reply to: op_thorsager

@tyler.warner @Curtis_Waguespack @WCrihfield Thank you all for the input! sorry for the late response - was on vacation for the past week 🙂 

as a reply to tyler - you can show the inspection dimension, input a label value and then disable inspection dimension - this will keep the label, but as a invisible value. This way you don't end up using inspection dimensions where they wouldn't be necessary.

 

 

This all look very interesting, and since i couldn't find any straight forward way to detect and delete specific dimensions depending on a given value, this will definitely help me along the way. I'm gonna have to test your solutions individually to figure out which one will be the most beneficial in my scenario, since my tool should require the least amount of userinput as possible, since i'm the only one at this company with any experience within inventor. for some reason they are still stuck on using autocad, even though it would be very beneficial for them to make the switch to 3d. The tool will hopefully act as a wakeupcall when its finished 

Message 6 of 6
WCrihfield
in reply to: op_thorsager

Hi @op_thorsager.  I am not sure if you are familiar with finding those dimensions again, once they have been assigned names using the Attribute system, so I attached a text file containing some iLogic code you could look at for retrieving DrawingDimensions that have been assigned names using attributes, as my code above is designed to do.  The main tool involved is the AttributeManager, and its FindObjects method.  These tools are included just under every Document object.  But it also includes the longer way to attempt to find named objects, in case you forgot the AttributeSet name &/or the Attribute name, but remember the name you gave to the dimension.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report