Dimensions in Triplicate

Dimensions in Triplicate

Anonymous
Not applicable
552 Views
7 Replies
Message 1 of 8

Dimensions in Triplicate

Anonymous
Not applicable

Greetings,

The following is a code that works great for dimensioning.  The issue I am having is that when I align the dimensions, the code appears to have run three times.  

This is what gets created.  (see screenshot below)  

 

So I was wondering if someone can identify how or why the dimensions I want are being put on the drawing three times?

 

I found this code from someone on this forum  It is not my original.   I do know that it searches all parameters and looks for the prefix that I have identified.  I did figure out a way to simply delete the extra dimensions, however, it would be nice to prevent the deletion step.

 

SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
 
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)


Dim PrefixStr As String = "RDT_"
 
Dim oGeneralDimension As GeneralDimension

For Each oGeneralDimension In oGeneralDimensionsEnum
    Dim oParameter As Parameter
    oParameter = oGeneralDimension.RetrievedFrom.Parameter
 
    If oParameter.DrivenBy.count <> 0 Then
        Dim oDrivenByParameter As Parameter
        For Each oDrivenByParameter In oParameter.DrivenBy
            If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
            End If
        Next
                Else
        If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
        End If
    End If
Next

 

 

 

 

 

 

 

 

Dimensiontimes3png.png

0 Likes
553 Views
7 Replies
Replies (7)
Message 2 of 8

wayne.brill
Collaborator
Collaborator

Hi,

 

Please post the code that is creating the dimensions. The code provided seems like it is code that is just deleting dimensions.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

Anonymous
Not applicable

That is the code that creates the dimensions.  It retrieves the dimensions from the model.

0 Likes
Message 4 of 8

wayne.brill
Collaborator
Collaborator

Hi,

 

I see what you mean now. I believe the problem you are seeing is that the .GeneralDimensions.Retrieve Method is creating too many dimensions.

 

I tried the code and I am not getting any duplicate dimensions in my tests. Please upload an assembly or part I can use to recreate this behavior. 

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

Anonymous
Not applicable

Wayne,

Attached is the part file.

I thought maybe some how I have the dimensions created three times.  However, that is not the case.  

 

Thanks for looking.

0 Likes
Message 6 of 8

wayne.brill
Collaborator
Collaborator

Hi,

 

Thanks for uploading the ipt. I am able to recreate the behavior where each dimension comes in triplicate. Here is an aproach that only creates 8 dimensions instead of 24. Maybe this could be a work around.

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

' Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
' oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oDrawView)

Dim oDims As GeneralDimensions
oDims = oSheet.DrawingDimensions.GeneralDimensions

Dim oRetrievableDims As ObjectCollection
oRetrievableDims = oDims.GetRetrievableDimensions(oDrawView)

MessageBox.Show(oRetrievableDims.Count.ToString(), "Title")

Dim oDimsToRetrieve As ObjectCollection
oDimsToRetrieve = ThisApplication.TransientObjects.CreateObjectCollection

Dim obj As Object

For Each obj In oRetrievableDims
    oDimsToRetrieve.Add(obj)
Next 

MessageBox.Show(oDimsToRetrieve.Count.ToString(), "Title")

If oDimsToRetrieve.Count > 0 Then
	oDims.Retrieve(oDrawView, oDimsToRetrieve)
End If

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 8

Anonymous
Not applicable

Wayne,

When I run this code I have 11 dimensions appear.  How do I identify the 6 that I want to appear instead of all 11?  Can I add the find dim with the "prefix string" part into your code?

 

You code does take care of the triplicate piece so thank you for that. Just need to be able to isolate the 6 that I want.

 

Thanks 

0 Likes
Message 8 of 8

wayne.brill
Collaborator
Collaborator

Hi,

 

I would use your code to delete the dimensions after they have been added. Here is what I tested with. With the ipt provided in a previous post I see five of the 8 dimensions getting deleted.

 

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oDrawView As DrawingView = oSheet.DrawingViews(1)

Dim oDims As GeneralDimensions
oDims = oSheet.DrawingDimensions.GeneralDimensions

Dim oRetrievableDims As ObjectCollection
oRetrievableDims = oDims.GetRetrievableDimensions(oDrawView)

'MessageBox.Show(oRetrievableDims.Count.ToString(), "Title")

Dim oDimsToRetrieve As ObjectCollection
oDimsToRetrieve = ThisApplication.TransientObjects.CreateObjectCollection

Dim obj As Object
For Each obj In oRetrievableDims
	oDimsToRetrieve.Add(obj)
Next 

'MessageBox.Show(oDimsToRetrieve.Count.ToString(), "Title")

Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
If oDimsToRetrieve.Count > 0 Then
	oGeneralDimensionsEnum = oDims.Retrieve(oDrawView, oDimsToRetrieve)
End If

Dim PrefixStr As String = "RDT_"
Dim oParameter As Parameter
Dim oGeneralDimension As GeneralDimension

For Each oGeneralDimension In oGeneralDimensionsEnum
    
    oParameter = oGeneralDimension.RetrievedFrom.Parameter
 	'MessageBox.Show(oParameter.Value, "Title")
    
	If oParameter.DrivenBy.count <> 0 Then
		'MessageBox.Show("Past oParameter.DrivenBy.count <> 0", "Title")
        Dim oDrivenByParameter As Parameter
        
		For Each oDrivenByParameter In oParameter.DrivenBy
            'MessageBox.Show("Past For Each oDrivenByParameter", "Title")
			If InStr(oDrivenByParameter.Name, PrefixStr) = 0 Then
                oGeneralDimension.Delete
				'This was never hit in my test - not sure if this For Each is needed
				MessageBox.Show("Deleted Dimension in For Each OParameter.DrivenBy loop", "Title")
            End If
        Next
                Else
        If InStr(oParameter.Name, PrefixStr) = 0 Then
            oGeneralDimension.Delete
			MessageBox.Show("Deleted Dimension in For Each oGeneralDimension loop", "Title")
        End If
    End If
Next

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes