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: 

Problem deleting unattached drawing dimensions with VBA

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
matinael
551 Views, 6 Replies

Problem deleting unattached drawing dimensions with VBA

Hello

I have a problem with inventor 2022 VBA macro. I can’t delete unattached drawing dimensions because all members attached value is True. But it shouldn’t be.

Is it Inventor 2022 bug or do i need to find new solution to delete unattached dimensions?

matinael_0-1629789033248.png

matinael_1-1629789047240.png

 

 

Labels (1)
6 REPLIES 6
Message 2 of 7
CattabianiI
in reply to: matinael

Could you please share a sample drawing with this issue?
Doing few tests on my side Attached property seems ok

Message 3 of 7
dutt.thakar
in reply to: matinael

@matinael 

Instead of deleting centerlines, can you try below?

 

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

Dim oDim As DrawingDimension
For Each oDim In oSheet.DrawingDimensions
	If oDim.Attached = False
		oDim.Delete
	End If
Next

 Try finding the dimensions that are not attached, the code is in VB.Net, you need to convert it in VBA, see if that helps. 

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


Regards,
Dutt Thakar
LinkedIn
Message 4 of 7
matinael
in reply to: matinael

Problem is chain dimensions set.  I guess that if they have some point attached then it would be like all the points are attached. It started when my firm updated 2021 vers. to 2022 vers.

I added also some sample file.

matinael_1-1629893986503.pngmatinael_2-1629894027401.png

 

 

Message 5 of 7
JMGunnar
in reply to: matinael

Create 1 try/ catch function 

OrdinateDimensionSets 

 

Best Reagards Johan

 

 

Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet
		Try
			Dim oDim As GeneralDimension
			For Each oDim In oSheet.DrawingDimensions
				If oDim.Attached = False
					oDim.Delete
				End If
			Next
		Catch
			Dim oDim As OrdinateDimensionSet
					
			
			For Each oDim In oSheet.DrawingDimensions.OrdinateDimensionSets
				If oDim.Attached = False
					oDim.Delete
				End If
			
			Next
		End Try

 

Message 6 of 7
CattabianiI
in reply to: matinael

Hi @matinael,

I tested your macro in Inventor 2020 and it has the same behaviour of Inventor 2022.
I came here just for the Inv 2022 update thing and it wasn't true. 😑

BTW, this is how to delete chain set dimensions in case of unattached points.
TL;DR: Check Intents and if it fails then merge dimensions.

 

Dim drwdoc As DrawingDocument = ThisApplication.ActiveDocument
For Each chainDim As ChainDimensionSet In drwdoc.ActiveSheet.DrawingDimensions.ChainDimensionSets
	
	Dim i = 0
	For Each genDim As GeneralDimension In chainDim.Members
		Try
			i = i + 1
		
			' I didn't test if this cast could fail sometimes.
			' [?] maybe angular dimension in chain set? Is it possible? I don't know!
			Dim linearDim As LinearGeneralDimension = TryCast(genDim, LinearGeneralDimension)
			If linearDim Is Nothing Then
				Continue For
			End If

			Try		
				Dim intent As GeometryIntent = linearDim.IntentOne
			Catch 			
				' Cannot retrieve the first geometry associated with the dimension
				
				If i = 1 Then
					' If it's the most left intent missing, I cannot merge dimensions so I delete it
					linearDim.Delete()		
				Else
					chainDim.MergeMembers(chainDim.Members(i - 1), linearDim)					
				End If 
				' Update the counter
				i = i - 1
			End Try
			
			' Working with last dimension
			If i = chainDim.Members.Count Then
				Dim latestDim As LinearGeneralDimension = chainDim.Members(i)
				Try	
					Dim intent As GeometryIntent = latestDim.IntentTwo
				Catch 				
					' it's the last intent missing so I delete the dimension
					latestDim.Delete()	
				End Try
				
				Return
			End If 

		Catch ex As Exception
			MsgBox(ex.ToString)	
		End Try
	Next
Next

 

Message 7 of 7
matinael
in reply to: CattabianiI

Thanks it works!

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

Post to forums  

Autodesk Design & Make Report