Retrieve driven dimensions ilogic

Retrieve driven dimensions ilogic

Anonymous
Not applicable
1,179 Views
5 Replies
Message 1 of 6

Retrieve driven dimensions ilogic

Anonymous
Not applicable

Hello Everybody,

i am trying to automate a drawing document. In this document I have a rule that retrieve dimensions like the one used here :

https://forums.autodesk.com/t5/inventor-customization/retrieve-dimensions/m-p/3650292

 

What this rule do is that it retrieves all dimensions and then search for the ones that include RetD_ as Prefix and keep them and delete the rest.

What I want to do is to keep driven dimensions also that have the Prefix : "RetD_". But this code seems to delete the driven dimensions even if I have modified the name and included RetD_ as a Prefix.

Can you please help ?

Thank you in advance.

0 Likes
Accepted solutions (2)
1,180 Views
5 Replies
Replies (5)
Message 2 of 6

Daan_M
Collaborator
Collaborator

Basically the code that worked perfectly in your other document, is not working for this document? right?

 

If it deletes everything it basically means that either (or both) of the If statements below is seen as true, you check which one (or both) of them is/are with a messagebox

 

If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
             oGeneralDimension.Delete
End If

If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
End If

 

 

 

 

 

 

 

Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Or, since you don't care which ones are driven, you could just eliminate that portion of the code and simplify it like this.

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oRetDims As GeneralDimensionsEnumerator = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)
Dim oPrefix As String = "RetD_"
Dim oGDim As GeneralDimension
Dim oParam As Parameter
For Each oGDim In oRetDims
	oParam = oGDim.RetrievedFrom.Parameter
	If Not oParam.Param.Name.StartsWith(oPrefix) Then
		oGDim.Delete
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

Anonymous
Not applicable

Hello @WCrihfield 

Thanks for your reply, yes clearing the two conditions and replacing them with one "if" test did solve the problem.

But i had to change your code a little bit in order to work:
instead of this line 

If Not oParam.Param.Name.StartsWith(oPrefix) Then

 I used "If Not oParam.Name.StartsWith(oPrefix) Then"

Thank you again,

Regards 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Hello @WCrihfield,

The above code is working perfectly with dimensions. But I added 3D annotations to the model, and this code is deleting them (3D dimensions). I am using 3D annotation because I need to have text as dimension : instead of having a value like 50 mm for example I want to write A1,B1 ....

Could you please advice how to resolve the problem ?

Thank you

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor
Accepted solution

OK.  So here's what needs to happen now:

  • Right after the For Each oGDim In oRetDims
    • you likely need to use a Select Case block of code to check if the oGDim.RetrievedFrom.Type against a list of all the possible types of model annotation objects (there are many)
    • You can either use a different Case statement for each possible variation, or you can use a single Case statement with commas (,) separating each variation (takes up less coding space)
    • Each variation will be like ObjectTypeEnum.kModelAnnotationObject, ObjectTypeEnum.kModelAnnotationTextObject, etc.
    • If the Type matches any of these, then don't delete it
    • Then use a Case Else to continue with the previously posted If...Then...Delete...End If code
    • Then use a End Select to close out the Select Case block
    • Then the final Next to close out the For Each loop.
    • You can find all the possible options here

Good luck.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)