Deleting only iLogic created Dimensions.

Deleting only iLogic created Dimensions.

krishnaprasad.veedu
Contributor Contributor
806 Views
8 Replies
Message 1 of 9

Deleting only iLogic created Dimensions.

krishnaprasad.veedu
Contributor
Contributor

Dear All,

I'm using the below ilogic rule to insert some dimensions into a view. My view has some dimensions which are manually added as well. I need your help to understand how I can have another rule to delete only these ilogic generated dimensions.  Thank you.

krishnaprasadveedu_0-1701764871963.png

 

 

Dim Sheet1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW11 = Sheet1.DrawingViews.ItemByName("V11")


Dim p1s0 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:1"}, "1")
Dim p1s1 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:2"}, "1")
Dim p1s2 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:4"}, "1")
Dim p1s3 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:5"}, "1")
Dim p1s4 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:3"}, "1")
Dim p1s5 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 130.5:1"}, "1")
Dim p1s6 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 130.5:2"}, "1")
Dim p1s7 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 130.5:3"}, "1")
Dim p1s8 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:6"}, "1")

Dim genDims = Sheet1.DrawingDimensions.GeneralDimensions
Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW11.SheetPoint(0.5, 1.13), p1s0, p1s1)
Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW11.SheetPoint(0.5, 1.035), p1s0, p1s2)
Dim linDim3 = genDims.AddLinear("Dimension 3", VIEW11.SheetPoint(0.5, 1.085), p1s2, p1s3)
Dim linDim4 = genDims.AddLinear("Dimension 4", VIEW11.SheetPoint(0.5, 1.035), p1s3, p1s4)
Dim linDim5 = genDims.AddLinear("Dimension 5", VIEW11.SheetPoint(0.5, 1.085), p1s4, p1s5)
Dim linDim6 = genDims.AddLinear("Dimension 6", VIEW11.SheetPoint(0.5, 1.035), p1s5, p1s6)
Dim linDim7 = genDims.AddLinear("Dimension 7", VIEW11.SheetPoint(0.5, 1.035), p1s6, p1s7)
Dim linDim8 = genDims.AddLinear("Dimension 8", VIEW11.SheetPoint(0.5, 1.085), p1s7, p1s8)
Dim linDim9 = genDims.AddLinear("Dimension 9", VIEW11.SheetPoint(0.5, 1.035), p1s8, p1s1)

 

 

0 Likes
Accepted solutions (1)
807 Views
8 Replies
Replies (8)
Message 2 of 9

JMGunnar
Collaborator
Collaborator

I create one  dimensionstyle "iLogicDimension"

then can i add this dimensionstyle too dimension then i create genDims.AddLinear

 

before i have function 

thats remove all Dimension with "iLogicDimension"

DeleteNamedDimensions(oDimensionStyles)

 

 

Best Regards Johan

 

@krishnaprasad.veedu 

 

Sub Main()

'''Default (ISO)
oDimensionStyles = "iLogicDimension"

Dim ds As DimensionStyle = ThisDrawing.Document.StylesManager.DimensionStyles.Item(oDimensionStyles)


Dim Sheet1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW11 = Sheet1.DrawingViews.ItemByName("V11")


DeleteNamedDimensions(oDimensionStyles)


Dim p1s0 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:1"}, "1")
Dim p1s1 = VIEW11.GetIntent({"Frame 1701180278888:1", "- 2400.5:2"}, "1")


Dim genDims = Sheet1.DrawingDimensions.GeneralDimensions
Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW11.SheetPoint(0.5, 1.13), p1s0, p1s1,DimensionTypeEnum.kVerticalDimensionType, dimensionStyle := ds)
Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW11.SheetPoint(0.5, 1.035), p1s0, p1s2)



	
End Sub 



Sub DeleteNamedDimensions(nameTag As String)
	 	Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet
		Dim ds As DimensionStyle = ThisDoc.Document.StylesManager.DimensionStyles.Item(nameTag)
		Try
			Dim oDim As GeneralDimension
			For Each oDim In oSheet.DrawingDimensions
				
				If oDim.Style Is ds Then
					oDim.Delete
				End If
			Next
		Catch
			Dim oDim As OrdinateDimensionSet
			For Each oDim In oSheet.DrawingDimensions.OrdinateDimensionSets
				If oDim.Style Is ds Then
					oDim.Delete
				End If
			Next

		End Try
End Sub


 

0 Likes
Message 3 of 9

g.georgiades
Advocate
Advocate

You can also use Attributes. When the dimension is created by code, apply an attribute to it which can then be read later on. This is good if you need different styles or want to change the styles afterwards.

 

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=DrawingDimension_AttributeSets 

https://modthemachine.typepad.com/my_weblog/2009/07/introduction-to-attributes.html

 

 

0 Likes
Message 4 of 9

krishnaprasad.veedu
Contributor
Contributor
Hi, Thank you? I'm more interested in the method using attributes, I have been trying to get it done but without success, would you be able to show me how to assign it in my example please?
0 Likes
Message 5 of 9

krishnaprasad.veedu
Contributor
Contributor
Thank you, I'll give it a try but does this mean that I will have to keep the same styles through out ?
0 Likes
Message 6 of 9

g.georgiades
Advocate
Advocate
Accepted solution

There are a few ways to do it, but the simplest in my mind is after each dimension creation, add an attribute group to the dimension. If you have 100s of dimensions, you will want to wrap it into a loop of some sort.

Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW1.SheetPoint(1.5, 1.035), Face0, Face1)
linDim2.NativeEntity.AttributeSets.Add("iLogicGenerated")

  Then in the other rule, simply check if the group exists.

For Each oDim As DrawingDimension In oSheet.DrawingDimensions
	If oDim.AttributeSets.NameIsUsed("iLogicGenerated") Then
		oDim.Delete()
	End If
Next

 

This should work for regular or ordinate dimensions.

If you need more granularity, you can actually add entries to the attribute group instead of just checking for it's existence.

 

 

Looking at Nifty Attributes, you may be able to skip the generation step entirely and just check if the iLogicEntityNameSet group exists since that is only created when using the iLogic IManagedDrawingDimensions Type.

ggeorgiades_0-1701781065255.png

 

 

0 Likes
Message 7 of 9

krishnaprasad.veedu
Contributor
Contributor
@g.georgiades : Thanks for your prompt reply, will give that a try. I'm quite new to Inventor and iLogic. Also, I wanted to ask if I can delete dimensions only from a particular sheet and view. I have got this code which deletes all dimensions from all the sheets. How do I modify it to delete, let's say View1 in the Sheet:2. Thank you.

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDim As DrawingDimension
Dim oTrans As Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument,"Delete")
For Each oDim In oSheet.DrawingDimensions
oDim.Delete
Next
0 Likes
Message 8 of 9

g.georgiades
Advocate
Advocate

If you look at @JMGunnar code, he has some code that grabs a specific sheet and view

 

This method you can only provide names for the sheet/view. You can not grab them by index.

Dim Sheet1 as IManagedSheet = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW11 as IManagedDrawingView = Sheet1.DrawingViews.ItemByName("V11")
Dim view1_Native as DrawingView = VIEW11.NativeEntity

 

If you do not know the names of the sheets or views, then you have to grab them a little differently. These also have different types. This method, you can provide a name or index for the sheet, but only an index for the view.

Dim viewOnSheet2 as DrawingView = ThisDrawing.Docuemnt.Sheets.Item(2).DrawingViews.Item(2)
Dim viewOnSheet2 as DrawingView = ThisDrawing.Docuemnt.Sheets.Item("Sheet:1").DrawingViews.Item(1)

 

Then in your loop to delete dimensions, you can check if the parent of the dimensions is the view you picked

This is a quite a bit trickier so I will link a post here

 

https://adndevblog.typepad.com/manufacturing/2012/08/how-to-determine-which-drawing-dimensions-belon...

 

 

0 Likes
Message 9 of 9

krishnaprasad.veedu
Contributor
Contributor

Hi, you were right, just by using the below code I was able to clear iLogic created dimensions. I did not have to assign them. Thanks a ton!

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDim As DrawingDimension

For Each oDim In oSheet.DrawingDimensions
    If oDim.AttributeSets.NameIsUsed("iLogicEntityNameSet") Then
        oDim.Delete()
    End If
Next
0 Likes