(iLogic) Delete Ordinate Dimension Set Member

(iLogic) Delete Ordinate Dimension Set Member

JoãoASilva
Advocate Advocate
2,071 Views
25 Replies
Message 1 of 26

(iLogic) Delete Ordinate Dimension Set Member

JoãoASilva
Advocate
Advocate

Hello all,

 

I'm trying to delete an Ordinate Dimension Set member with iLogic.

I can delete the whole Dimension Set if there is a "sick" dimension, but that would give me even more work 😄

JoãoASilva_0-1612866591008.png

I tried deleting unattached center marks first, but it doesn't solve anything.

 

Any tips?

João Silva

Mechanical Engineer

 

0 Likes
Accepted solutions (1)
2,072 Views
25 Replies
Replies (25)
Message 2 of 26

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

I tried with a small test with ordinate dimensions and below code and it is identifying if the center mark is unattached it will delete it and that specific dimension as well. Can you check it and see if that's something you are looking for?

 

Dim oDoc As DrawingDocument
    oDoc = ThisDoc.Document 'ThisServer.ActiveDocument
    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
    Dim oCM As Centermark
    For Each oCM In oSheet.Centermarks
        If oCM.Attached = False Then
            Call oCM.Delete
        End If
    Next  

 

Hope this will help.

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 26

JoãoASilva
Advocate
Advocate

@dutt.thakar 

I have the same code to delete sick center marks:

For Each oCM As Centermark In ActiveSheet.Sheet.Centermarks
	If oCM.Attached = False Then
		oCM.Delete
	End If
Next

I'm using the Ordinate Dimension Set, not the Ordinate Dimension.

JoãoASilva_0-1612868980717.png

With this type of Ordinate Dimension, deleting the center mark doesn't delete the sick member.

 

João Silva

Mechanical Engineer

 

0 Likes
Message 4 of 26

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

Please see the below screencast. I have given "Ordinate Set" only and by deleting the Centermark with above iLogic code only, it is deleting a sick member from the ordinate set.

 

 

https://knowledge.autodesk.com/community/screencast/88d10760-a75c-4e48-a26c-de2341178c73

 

 

 

 
If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 26

matt_jlt
Collaborator
Collaborator

If you are just trying to delete all broken dimensions this should work

' Check active document is a drawing document
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("A drawing document must be open", "Broken Dimension Delete")
	Exit Sub
End If

' Get drawing document
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

' Iterate through all sheets in document
For Each oSheet As Inventor.Sheet In oDoc.Sheets
	' Iterate through all dimensions in sheet
	For Each oDim As Inventor.DrawingDimension In oSheet.DrawingDimensions
		' Check dimension is attached / broken
		If oDim.Attached = False Then
			' Delete Dimension
			oDim.Delete
		End If
	Next
Next

But if you only want to delete ordinate set dimensions and no other dimensions you just need to check the property like this

' Check active document is a drawing document
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("A drawing document must be open", "Broken Dimension Delete")
	Exit Sub
End If

' Get drawing document
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

' Iterate through all sheets in document
For Each oSheet As Inventor.Sheet In oDoc.Sheets
	' Iterate through all dimensions in sheet
	For Each oDim As Inventor.DrawingDimension In oSheet.DrawingDimensions
		If oDim.Type = Inventor.ObjectTypeEnum.kOrdinateDimensionObject Then
			
			' Set dimension to ordinate dimension (not necessary but helps intellisense when coding)
			Dim oOrdDim As Inventor.OrdinateDimension = oDim
			
			' Check dimension is a member of an ordinate dimension set and if it's attached
			If oOrdDim.IsOrdinateSetMember And  oDim.Attached = False
				' Delete Dimension
				oDim.Delete
			End If
			
		End If
	Next
Next
0 Likes
Message 6 of 26

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

I also have investigated something else, if you are using center marks to give ordinate set dimensions, deleting the center mark will also delete the ordinate set member attached to it, but if you are using the hole edge or any edge to give dimension and not the center mark, below loop can be helpful. It needs to access the member of the ordinate set and check if the dimension is sick, it has to delete the specific member. See below code.

 

 

    
    For Each oDrawingDim As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
        For Each oMember As OrdinateDimension In oDrawingDim.Members
		If oMember.Attached = False Then
                Call oMember.Delete
        End If
	Next
    Next
If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 7 of 26

JoãoASilva
Advocate
Advocate

@matt_jlt 

That's more or less the code I have right now.

I'm trying do add an exception so it deletes only sick members, and not the full Dimension Ordinate Set.

 

 

@dutt.thakar 

You are right about using the center mark to give the dimension.

I tested a few ways and, if I use the center mark for the dimension, it disappears without any issue (like your screencast).

 

The thing is that, for speed purposes, I click and drag to the left (selection box) so I get all the lines and holes I want.

 

Also, at first glance your code seems right, but it returns an "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))".

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document 'ThisServer.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oCM As Centermark

For Each oCM In oSheet.Centermarks
    If oCM.Attached = False Then
        oCM.Delete
    End If
Next

For Each oDrawingDim As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
    For Each oMember As OrdinateDimension In oDrawingDim.Members
		If oMember.Attached = False Then
        	oMember.Delete
		End If
	Next
Next  

 Am I missing anything?

João Silva

Mechanical Engineer

 

0 Likes
Message 8 of 26

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

Is it possible to upload your component and drawing?

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 9 of 26

matt_jlt
Collaborator
Collaborator

The code i posted should only delete a single member that has broken (I have tested it out and it only deletes each broken individual member and not the whole set) Are you not getting the same behavior?

 

You mentioned you are doing a selection then running the code on that? Can you post your code so we can help you get it working? Just makes it easier than trying to guess what you are doing.

 

 

0 Likes
Message 10 of 26

JoãoASilva
Advocate
Advocate

@dutt.thakar 

I've attached them for you to try.

I should also mention that I'm using Inventor 2021.

 

@matt_jlt 

In my screencast you can see that I'm getting an error with your rules. The error only occurs when there are sick dimensions. If there are none, the rule completes without any problem.

By selection I meant the way I select holes and lines to get the Dimension Set to attach to where I want. (see screencast from 0.08s - 0.10s)

 

https://knowledge.autodesk.com/community/screencast/84175e8f-12ef-493a-a0e3-23b88455d8ca

 

@dutt.thakar , @matt_jlt 

I've also made a simple msgbox to show me the 'oMember.Attached' property behaviour.

It seems that, if there are no sick members, all members return a value of 'True'.

If there is at least 1 sick member, all members return a value of 'False'.

Screencast below and the code I used.

 

https://knowledge.autodesk.com/community/screencast/e8f88b98-f292-484c-93f5-0b3fbf3fed68

 

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document 'ThisServer.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oCM As Centermark

For Each oDrawingDim As OrdinateDimensionSet In oSheet.DrawingDimensions.OrdinateDimensionSets
    For Each oMember As OrdinateDimension In oDrawingDim.Members
		MsgBox("Value: " & oMember.Text.Text & vbNewLine & vbNewLine & _
		"Attached: " & oMember.Attached.ToString, , "Dimension:")
	Next
Next

I hope i'm being dumb about this, otherwise this seems like a dumb behaviour.

João Silva

Mechanical Engineer

 

0 Likes
Message 11 of 26

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

Tested the code with your part and drawing, see below GIF.

 

 

Oridinate Dims Delete.gif

I would also advise, for a normal dimension that is not in the Ordinate sets, add the below lines in the code, to delete them as well.

 

For Each oDDim As DrawingDimension In oSheet.DrawingDimensions
    
		If oDDim.Attached = False Then
        	oDDim.Delete
		End If
Next

 I am not sure, but the problem could be because of the selection you are doing, as it is actually taking both Center marks and edges as well. Not certain but try avoiding them and check the code, please. I would also suggest using one, either center marks or edges to give the dimension.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 12 of 26

JoãoASilva
Advocate
Advocate

@dutt.thakar 

 

First, let me thank you for sticking with me, even seeming like I'm failing at something so easy.

 

Before I get frustrated with myself, can you confirm how you set up you Ordinate Dimension Set:

Did you select the hole geometry or the centermark?

Did you try with all other holes and got the same result?

 

In the first screencast I sent, you can see how I set up the dimensions. I am careful to choose geometry and/or centermarks. [00:05 - 00:21]

When I run your rule [01:00], all the dimensions that used centermark has anchor point, got deleted as expect.

 

I've tried deleting the hole centermark in the part document, instead of deselecting it, just like you did.

Still the same outcome.

 

I'll continue to test all the possible ways to create a hole and dimension it.

João Silva

Mechanical Engineer

 

0 Likes
Message 13 of 26

JoãoASilva
Advocate
Advocate

@dutt.thakar 

 

I've changed my files to better visualize how the hole disappears, and how the drawing is created. (find the new files attached, with the same name)

 

https://knowledge.autodesk.com/community/screencast/610d5060-9f34-4e38-8be4-fd7231b2a0a0

^ This screencast also shows what i'm doing and how, and the final result after running your rule.

 

Legend (Top):

The 3 holes on the left, I delete the part sketch centermark; [Delete]

The 3 holes on the right, I deselect in the hole command; [Deselect]

The center hole is just to prevent an error when all holes are deleted.

 

Legend (Bottom):

[Geometry] to select geometry when creating the Ordinate Set;

[Centermark] to select centermark when creating the Ordinate Set;

[Both] is to select both geometry and centermark (wich is the method I usally use, so I don't need to be that precise in selecting);

 

I don't want to seem condescending, I just want to lay all the info so you can point out where I'm getting wrong.

 

Many thanks 👍

João Silva

Mechanical Engineer

 

0 Likes
Message 14 of 26

matt_jlt
Collaborator
Collaborator

I tested my code out a bunch of times and it works every time with the exception of throwing an error when you are deleting the "origin" member. I guess it would need some kind of additional checking to do that which i'm not 100% sure on sorry. I guess you could then search through all the dimension sets to see if it matches the origin member as i doesn't seem like there is a simple property identifying this in the individual member.

 

I can only test in inventor 2019 at the moment so there may be different issues compared to your version.

 

Looking at your screencast, can you click on the "more info" tab and post that infor when you are running the rule from Dutt? it might help us work out what is triggering the error.

0 Likes
Message 15 of 26

JoãoASilva
Advocate
Advocate

@matt_jlt ,

 

I'm sorry for the delayed reply, I got really busy last week out of the blue.

I'll be working today towards your sugestion.

 

Also, here's the "more info" message:

Screenshot_1.png

João Silva

Mechanical Engineer

 

0 Likes
Message 16 of 26

matt_jlt
Collaborator
Collaborator

Ok, so it looks like the issue is the command deleting the dimension. I am guessing its the same / similar issue with my code that you are getting where it is trying to delete the origin dimension. I could be wrong but that's my best guess.

 

The code below is updated to check for origin members and skip them, to prevent you losing all of the dimensions in the set. I also added try / catch in there with a transaction so you can undo / redo all dimension deleted items in a single click. makes it easier to undo if you have lots of broken dimensions.

 

' Check active document is a drawing document
If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("A drawing document must be open", "Broken Dimension Delete")
	Exit Sub
End If

' Get drawing document
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

' Create a new transaction
Dim oTX As Inventor.Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Delete Dimensions - iLogic")

Try
	
' Iterate through all sheets in document
For Each oSheet As Inventor.Sheet In oDoc.Sheets
	' Iterate through all dimensions in sheet
	For Each oDim As Inventor.DrawingDimension In oSheet.DrawingDimensions
		If oDim.Type = Inventor.ObjectTypeEnum.kOrdinateDimensionObject Then
			
			' Set dimension to ordinate dimension (not necessary but helps intellisense when coding)
			Dim oOrdDim As Inventor.OrdinateDimension = oDim

			' Check dimension is a member of an ordinate dimension set and if it's attached
			If oOrdDim.IsOrdinateSetMember And oDim.Attached = False
				' Check if dimension is an origin member, skip if it is to allow user to manually fix
				' If you don't want to manually fix them, you can iterate through all dim sets and check all origin members if they are attached
				' This will prevent any crashes in the code, you can't delete a set as you are iterating through all dimensions because it deletes
				' referenced objects from the set you are searcing through and causes it to crash / throw an error
				If oOrdDim.OrdinateDimensionSet.OriginMember Is oOrdDim Then Continue For
				' Delete Dimension
				oDim.Delete
			End If
			
		End If
	Next
Next

Catch ex As Exception
	MessageBox.Show(ex.Message, "Delete Dimensions - iLogic")
Finally
	oTX.End
End Try

 

0 Likes
Message 17 of 26

JoãoASilva
Advocate
Advocate

@matt_jlt ,

 

Thanks for the quick response.

 

The code is neat, but Inventor is working in an odd way.

From what I have been testing so far, if one member isn't attached, all members return a

oDim.Attached = False

 The code skips the origin, but deletes every member (attached or not) until all sick members are gone.

The code I was testing does the same thing.

 

It seems that Inventor is checking if the OrdinateDimension has non attached members and, if it has, it deletes the next member.

And it continues until there are no non attached members.

 

I don't know if this is supposed to work this way though...

 

@chandra.shekar.g , could you chime in?

João Silva

Mechanical Engineer

 

0 Likes
Message 18 of 26

matt_jlt
Collaborator
Collaborator

I can only suggest that the behavior in inventor 2019 / 2020 is different or there is a bug in your version. I just triple checked the code and I am not getting the same results as you. I have tried it with the following combinations and not had one error.

 

- all members detached - result : deletes all members but the origin member

- origin member only detached : skips origin member and leaves all other dimensions

- non-origin members detached: deletes only detached members

 

I don't think i can offer any other assistance if it is a software bug sorry. Hopefully autodesk get back to you or someone else works something out.

0 Likes
Message 19 of 26

JoãoASilva
Advocate
Advocate

@matt_jlt 

 

You have been really helpful!

 

One last thing I need to ask:

Have you selected geometry and centermarks?

 

I'll open Inventor 2020 and test there as well.

João Silva

Mechanical Engineer

 

0 Likes
Message 20 of 26

JoãoASilva
Advocate
Advocate

@matt_jlt , @dutt.thakar 

 

I've just checked on Inventor 2020, and there is no error ocurring.

Seems like my version of Inventor 2021 is bugged.

 

 

@YuhanZhang@MjDeck@adam.nagy 

I took the liberty of tagging you guys so I can get a faster response.

Hope i'm not misusing my tagging privileges here.

João Silva

Mechanical Engineer

 

0 Likes