.NET

Reply
Distinguished Contributor
HJohn1
Posts: 170
Registered: ‎09-26-2008
Message 1 of 11 (879 Views)
Accepted Solution

DIMSCALE problem

879 Views, 10 Replies
05-13-2013 07:54 AM

Hi, I am having problems with dimension after changing the dimscale.  The user wants to change the dimscale.  The program prompts for the selection of a dimension entity and also for the new dimscale.  The dimscale property of the dimension entity is set to the new dimscale.  The problem is that the entity is not updated on the screen, even after calling the entity draw method.  In VBA there was an Update method, but I can find anything like that in the .NET dimension entity.  Can someone help me with this situation? I will really appreciate your help.

Hi John,

 

Here is a sample code that I tried with AutoCAD 2012 and the dimension scale took effect correctly.

This is a cleaned up version of your code and most of it are suggestions that DP had already provided.

 

 <CommandMethod("BR")> _
Public Sub DimensionUpdateMethod()
Dim activeDoc As Document
activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor
ed = activeDoc.Editor
Dim peo As PromptEntityOptions
peo = New PromptEntityOptions(vbCrLf & "Please select a dimension: ")
peo.SetRejectMessage("Please select dimensions only.")
peo.AddAllowedClass(GetType(Dimension), False)
Dim Id As ObjectId
Dim per As PromptEntityResult
per = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Dim NewDimScale As Double
NewDimScale = 3.0
Id = per.ObjectId
Using Trans As Transaction = activeDoc.TransactionManager.StartTransaction
Dim BlkTbl As BlockTable
BlkTbl = CType(Trans.GetObject(activeDoc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
Dim BlkTabr As BlockTableRecord
BlkTabr = CType(Trans.GetObject(BlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Dim Ent As Entity
Ent = CType(Trans.GetObject(Id, OpenMode.ForWrite), Entity)
Dim dimension As Dimension
dimension = CType(Ent, Dimension)
dimension.Dimscale = NewDimScale
Trans.Commit()
End Using
End Sub

 

So, It appears that the issue you are having is specific to AutoCAD Mechanical and there are a few features that do behave differently in the verticals.

http://docs.autodesk.com/AMECH_PP/2014/ENU/index.html?url=files/GUID-7B1C5317-E960-49C8-A2F0-D32E2D6F4BA1.htm,topicNumber=d30e22165

 

In the above post, please refer to "Special Notes on DIMLFAC & DIMSCALE"

 

Sorry, I dont have a solution to get it working in AutoCAD Mechanical and an expert in the AutoCAD Mechanical discussion forum might be able to help.

 

 

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 2 of 11 (838 Views)

Re: DIMSCALE problem

05-16-2013 04:43 AM in reply to: HJohn1

Hi John,

 

Can you please try using the "DimRegen" command ?

 

<code>
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("DIMREGEN ", true, false, false);
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("REGEN ", true, false, false);
</code>

 The other way to ensure that the update happens is described here:

http://adndevblog.typepad.com/autocad/2013/01/force-autocad-to-update-the-graphics-display-area.html

 



Balaji
Developer Technical Services
Autodesk Developer Network

Distinguished Contributor
HJohn1
Posts: 170
Registered: ‎09-26-2008
Message 3 of 11 (825 Views)

Re: DIMSCALE problem

05-16-2013 10:10 AM in reply to: Balaji_Ram

Balaji thank you for your suggestions.  I tried them all and the dimension still is not updated on the screen. What I want to do is something like selecting a dimension from the drawing, opening the properties window and changing the dimension overall dimscale.  The dimension entity is updated immediately after.  Here is my code, if you could say what I am doing wrong I will really appreciate.  Thanks in advance.

 

Try

	Using Trans As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction

		peo = New PromptEntityOptions(vbCrLf & "Please select a dimension: ")

		peo.SetRejectMessage("Please select dimensions only.")

		peo.AddAllowedClass(GetType(Dimension), False)

		peo.AddAllowedClass(GetType(AlignedDimension), False)

		peo.AddAllowedClass(GetType(RotatedDimension), False)

		peo.AddAllowedClass(GetType(ArcDimension), False)

		peo.AddAllowedClass(GetType(RadialDimension), False)

		peo.AddAllowedClass(GetType(OrdinateDimension), False)

		per = Ed.GetEntity(peo)

		If per.Status = PromptStatus.OK Then

			Id = per.ObjectId

		Else

			Return False

		End If

		BlkTbl = CType(Trans.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable)

		BlkTblr = CType(Trans.GetObject(BlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)

		Ent = CType(Trans.GetObject(Id, OpenMode.ForWrite), Entity)

		If TypeOf (Ent) Is AlignedDimension Then

			AlignDim = CType(Ent, AlignedDimension)

			AlignDim.Dimscale = NewDimScale

		ElseIf TypeOf (Ent) Is RotatedDimension Then

			RotatedDim = CType(Ent, RotatedDimension)

			RotatedDim.Dimscale = NewDimScale


		ElseIf TypeOf (Ent) Is ArcDimension Then

			ArcDim = CType(Ent, ArcDimension)

			ArcDim.Dimscale = NewDimScale

		ElseIf TypeOf (Ent) Is RadialDimension Then

			RadialDim = CType(Ent, RadialDimension)

			RadialDim.Dimscale = NewDimScale

		ElseIf TypeOf (Ent) Is OrdinateDimension Then

			OrdinateDim = CType(Ent, OrdinateDimension)

			OrdinateDim.Dimscale = NewDimScale

		End If

		Ent.Draw()

		Trans.Commit()

		Trans.TransactionManager.QueueForGraphicsFlush()

		Application.DocumentManager.MdiActiveDocument.SendStringToExecute("DIMREGEN", True, False, False)

        Application.DocumentManager.MdiActiveDocument.SendStringToExecute("REGEN", True, False, False)
						
		Autodesk.AutoCAD.Internal.LayerUtilities.RegenLayers({Ent.LayerId}, Autodesk.AutoCAD.Internal.LayerUtilities.RegenPending)

	End Using

	Return True

Catch ex As Exception

	 MessageBox.Show(ex.Message, "DimScale Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally

	DocLock.Dispose()

End Try

 

 

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 11 (821 Views)

Re: DIMSCALE problem

05-16-2013 12:44 PM in reply to: HJohn1

You don't need most of that code if you only want to update the dimension scale.

 

The Dimscale property is a property of the Dimension base type, so you don't need all of that if/then/else business that tests the type and casts it to the concrete dimension type.

 

Just open the selected object and cast it to a Dimension (you don't have to check it first because you're using AddAllowedClass). 

 

After you cast the selected object to a Dimension, and set its Dimscale, call the GenerateLayout() method.

Distinguished Contributor
HJohn1
Posts: 170
Registered: ‎09-26-2008
Message 5 of 11 (798 Views)

Re: DIMSCALE problem

05-17-2013 05:58 AM in reply to: DiningPhilosopher

DPhilosopher thank you for your suggestion, the unnecessary code as well.  However, this still is not solving the issue. The screen is updated, but the dimensions are in limbo state.  They are visible on the screen but they can not be selected, even after calling the regen command. Any suggestion on how to solve this issue.

Distinguished Contributor
HJohn1
Posts: 170
Registered: ‎09-26-2008
Message 6 of 11 (789 Views)

Re: DIMSCALE problem

05-17-2013 01:54 PM in reply to: HJohn1

I forgot to mention that I am using AutoCAD mechanical 2012.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 7 of 11 (772 Views)

Re: DIMSCALE problem

05-17-2013 07:55 PM in reply to: HJohn1

The code you posted contains a collection of hacks that aren't working, but you didn't bother removing them.

 

The first hack you need to remove is this:

      Ent.Draw()

 

Second, don't use the TransactionManager from HostApplicationServices.WorkingDatabase. 

 

Use the active document's Transaction manager, and remove the call to QueueForGraphicsFlush(), since the Transaction takes care of that.

 

Lastly, get rid of the call to SendStringToExecute() to run the DIMREGEN command.

 

If you're going to hack by trying various things, and they don't solve the problem, don't leave them in the code.

 

 

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 8 of 11 (755 Views)

Re: DIMSCALE problem

05-19-2013 10:58 PM in reply to: HJohn1

Hi John,

 

Here is a sample code that I tried with AutoCAD 2012 and the dimension scale took effect correctly.

This is a cleaned up version of your code and most of it are suggestions that DP had already provided.

 

        <CommandMethod("BR")> _
        Public Sub DimensionUpdateMethod()

            Dim activeDoc As Document
            activeDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor
            ed = activeDoc.Editor
            Dim peo As PromptEntityOptions
            peo = New PromptEntityOptions(vbCrLf & "Please select a dimension: ")
            peo.SetRejectMessage("Please select dimensions only.")
            peo.AddAllowedClass(GetType(Dimension), False)

            Dim Id As ObjectId
            Dim per As PromptEntityResult
            per = ed.GetEntity(peo)
            If per.Status <> PromptStatus.OK Then
                Return
            End If

            Dim NewDimScale As Double
            NewDimScale = 3.0

            Id = per.ObjectId

            Using Trans As Transaction = activeDoc.TransactionManager.StartTransaction

                Dim BlkTbl As BlockTable
                BlkTbl = CType(Trans.GetObject(activeDoc.Database.BlockTableId, OpenMode.ForRead), BlockTable)

                Dim BlkTabr As BlockTableRecord
                BlkTabr = CType(Trans.GetObject(BlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)

                Dim Ent As Entity
                Ent = CType(Trans.GetObject(Id, OpenMode.ForWrite), Entity)

                Dim dimension As Dimension
                dimension = CType(Ent, Dimension)
                dimension.Dimscale = NewDimScale

                Trans.Commit()
            End Using
        End Sub

 

So, It appears that the issue you are having is specific to AutoCAD Mechanical and there are a few features that do behave differently in the verticals.

http://docs.autodesk.com/AMECH_PP/2014/ENU/index.html?url=files/GUID-7B1C5317-E960-49C8-A2F0-D32E2D6...

 

In the above post, please refer to "Special Notes on DIMLFAC & DIMSCALE"

 

Sorry, I dont have a solution to get it working in AutoCAD Mechanical and an expert in the AutoCAD Mechanical discussion forum might be able to help.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 9 of 11 (750 Views)

Re: DIMSCALE problem

05-20-2013 12:12 AM in reply to: Balaji_Ram
Hi Balaji.

In the interest of promoting best practices, you wouldn't cast the DBObject returned by GetObject() to an Entity first, and then to a Dimension. You would just cast it to a Dimension, since you can assume that it is one.
ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 10 of 11 (747 Views)

Re: DIMSCALE problem

05-20-2013 12:32 AM in reply to: DiningPhilosopher

Hi DP,

 

You are right, casting it twice is not needed.

Thanks for correcting that.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.