Rule doesn't work for removing extra dimensions

Rule doesn't work for removing extra dimensions

jsternamanLULAE
Participant Participant
699 Views
6 Replies
Message 1 of 7

Rule doesn't work for removing extra dimensions

jsternamanLULAE
Participant
Participant

How do I remove the unwanted dimensions after I shorten my piece on the drawing?  When I shorten the part and holes go aways but the dimensions stay and turn magenta.  How do I remove the dimensions.  The code I have does not work.  It works from my local files but not from vault.

This is the error I get when I open drawing from vault...

jsternamanLULAE_0-1695989656138.png

This is the code that I found that should but does not work...

jsternamanLULAE_1-1695989725126.png

This the view before....

jsternamanLULAE_2-1695989879722.png

This is after and want the dimensions removed before drawing is saved.

jsternamanLULAE_3-1695989928731.png

 

0 Likes
Accepted solutions (1)
700 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

What does the second tab of that error message say.  The second tab of the error message sometimes contains more useful, and more detailed information about the error, and sometimes that will give us a clue as to where the error happened also.  Did running that shown rule on that drawing cause the dimensions to turn magenta, or were the dimensions already magenta before trying to run that rule on that drawing?  There is a way to find only the dimensions that are sick like that, and get rid of them.  We can check the DrawingDimension.Attached property, which is a ReadOnly Boolean type value.  They provide an example VBA macro code for removing dimensions that are not attached to anything also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

jsternamanLULAE
Participant
Participant

This is the second tab...

jsternamanLULAE_1-1695992244196.png

Running the rule did not make dimensions magenta.  I shortened the part which is remove couple holes.  This is what makes the dimensions turn magenta.  I need the magenta dimensions to go away.  How do I remove the magenta dimensions?  

 

Thanks,

Jeff S.

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor
Accepted solution

OK.  That additional error data indicates that the error is happening when it tries to execute the DrawingDimension.Delete method.  So, there must be at least one dimension that is giving this routine that problem.  My guess is that it might be the first OrdinateDimension shown in the image.  I just created a quick drawing view and added an OrdinateDimensionSet to the view, with multiple members.  Then I created a quick, simple iLogic rule to loop through all generic DrawingDimensions on the sheet, and delete them.  It threw the exact same error.

You could try this very similar iLogic rule, which includes a Try...Catch block to avoid the potential error, and let the rule continue.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oDDims As DrawingDimensions = oDDoc.ActiveSheet.DrawingDimensions
For Each oDDim As DrawingDimension In oDDims
	If oDDim.Attached = False Then
		Try
			oDDim.Delete
		Catch
		End Try
	End If
Next 'oDDim

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 5 of 7

GosponZ
Collaborator
Collaborator

Here is one more for pink dimensions

'This code deletes unattached dimensions

    ' Set a reference to the active drawing document
    Dim oDoc As DrawingDocument
    oDoc = ThisDoc.Document 'ThisServer.ActiveDocument
    
    ' Set a reference to the active sheet
'    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
    
  
    ' Iterate over all dimensions in the drawing
    ' and delete unattached (sick) dimensions.
    
    For Each oDrawingDim In oSheet.DrawingDimensions
        If oDrawingDim.Attached = False Then
            Call oDrawingDim.Delete
        End If
		Next
0 Likes
Message 6 of 7

jsternamanLULAE
Participant
Participant

At first I got these to work and now they are not working.  I have the rule placed in the "After Open Document" in the event triggers.

jsternamanLULAE_0-1696423675518.png

 

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Hi @jsternamanLULAE.  Is it throwing an error when it does not work?  If so, please include what the 'More Info' tab of the error message says.  Do you believe it is possible that it is deleting some, but not all of the unattached dimensions?  If that is the case, then we may need to either create a more detailed routine that checks what more specific derived type each dimension is, then react appropriately.  Or we may need to put that whole loop and delete routine out into a separate Function type routine, so that it can be called multiple times in a loop, until it no longer makes any changes.  One of the potential problems is that you are not allowed to delete the first dimension in a set.  So if you have any OrdinateDimensionSets, then you can not delete just the first OrdinateDimension from each OrdinateDimensionSet.  If you have any BaseLineDimensionSets, you can not delete the first dimension from each BaseLineDimensionSet, and so on.  So, in those cases, if that first dimension in a set is not attached you may have to delete the whole set, instead of just the one dimension.

 

Edit:  Another thing that comes to mind is that the views may have not had time to update before that code ran.  What I mean is that views can be forced to update due to changes that happened in the model, and when those changes happen, that may cause some dimensions to no longer be attached.  Well, if that updating of the views happens after the rule already ran, the rule would not have known about the dimensions not being attached.  I am not sure if the 'after open' event is triggered, running that rule, before the views get updated or not.  Just a thought.  If you run that rule manually after that point in time, does it work on that drawing then?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes