Jump to content

Selecting all Dimensions and changing Dim Style


rjohnson42

Recommended Posts

Hey Fellas,

 

After selecting the appropriate dimensions, I would like to be able to change the entity's dim style. I cannot figure out how to do this and I would appreciate any help/feedback. Here's what I have so far:

 

Public Sub MakeSelectionLayerMETRIC()
       Dim myDWG As Document = DocumentManager.MdiActiveDocument
       Dim myPSR As PromptSelectionResult = myDWG.Editor.GetSelection
       If myPSR.Status = PromptStatus.OK Then
           Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
               For Each myObjectID As ObjectId In myPSR.Value.GetObjectIds
                   Dim myEntity As Entity = myObjectID.GetObject(OpenMode.ForWrite)
                   myEntity.Layer = "TEXT METRIC"

               Next
               myTrans.Commit()
           End Using
       End If
   End Sub

 

I'll have to start a new transaction for this to work, right? Could someone show me how to do this within the same subroutine?

 

Thanks

Link to comment
Share on other sites

The current transaction should be fine, but you may want to cast the entity as a dimension:

 

       Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument
       Dim myPSR As PromptSelectionResult = myDWG.Editor.GetSelection
       If myPSR.Status = PromptStatus.OK Then
           Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
               For Each myObjectID As ObjectId In myPSR.Value.GetObjectIds
                   Dim myEntity As Dimension = DirectCast(myObjectID.GetObject(OpenMode.ForWrite), Dimension)
                   myEntity.Layer = "TEXT METRIC"
                   myEntity.DimensionStyleName = "Metric" ‘Or whatever

               Next
               myTrans.Commit()
           End Using
       End If

It may also be sensible to make sure both the layer and the dimension style do exist.

Link to comment
Share on other sites

Another safety precaution would be to insure you are actually dealing with dimension entities. Using selection filters, Try/Catch blocks, or TryCast (instead of DirectCast) would be some of the options.

Link to comment
Share on other sites

Another safety precaution would be to insure you are actually dealing with dimension entities. Using selection filters, Try/Catch blocks, or TryCast (instead of DirectCast) would be some of the options.

 

Eventually, I went for a filter:

 

Public Sub MakeSelectionLayerMETRIC()
       Dim myDWG As Document = Application.DocumentManager.MdiActiveDocument
       Dim myEd As Editor = DocumentManager.MdiActiveDocument.Editor
       Dim myTVs(0) As TypedValue
       myTVs(0) = New TypedValue(DxfCode.Start, "Dimension")
       Dim myFilter As New SelectionFilter(myTVs)
       Dim myPSR As PromptSelectionResult = myEd.SelectAll(myFilter)
       If myPSR.Status = PromptStatus.OK Then
           Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
               For Each myObjectID As ObjectId In myPSR.Value.GetObjectIds
                   Dim myEntity As Dimension = DirectCast(myObjectID.GetObject(OpenMode.ForWrite), Dimension)
                   myEntity.Layer = "TEXT METRIC"
                   myEntity.DimensionStyleName = "METRIC"
               Next
               myTrans.Commit()
           End Using
       End If
   End Sub

 

You also mentioned that it would be sensible to check if the layer/dimension style exist. I have two subroutines before this one that create them; is it safe to rely on the order that the subroutines are initiated? Should I place a check within the above code?

Edited by rjohnson42
spelling
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...