rjohnson42 Posted January 10, 2011 Share Posted January 10, 2011 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 Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 10, 2011 Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
rjohnson42 Posted January 10, 2011 Author Share Posted January 10, 2011 It may also be sensible to make sure both the layer and the dimension style do exist. Ah, casting. Great, thanks! Quote Link to comment Share on other sites More sharing options...
SEANT Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
rjohnson42 Posted January 11, 2011 Author Share Posted January 11, 2011 (edited) 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 January 11, 2011 by rjohnson42 spelling Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.