Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotate UCS in .net

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Giri_kani
2018 Views, 9 Replies

Rotate UCS in .net

I need to rotate UCS as "(command "_.UCS" "_Z" degree)" in .net..

 

Please help me

9 REPLIES 9
Message 2 of 10
Ajilal.Vijayan
in reply to: Giri_kani
Message 3 of 10
Giri_kani
in reply to: Ajilal.Vijayan

This is working fine..Thanks for your solution...
Message 4 of 10
Giri_kani
in reply to: Ajilal.Vijayan

After changing UCS Z , i want to place some entities like block,line,polyline and so on..

But those entities are not rotating correctly based on UCS Z axis..

 

How to place an entity after changing UCS in .net?

Message 5 of 10
Ajilal.Vijayan
in reply to: Giri_kani

Transform all the entities points to draw in the new coordinate system.

 

Use TransformBy

'' Create a line that starts at 5,5 and ends at 12,3
            Dim acLine As Line = New Line(New Point3d(5, 5, 0).TransformBy(Rot), _
                                          New Point3d(12, 3, 0).TransformBy(Rot))

 

 

Have a look at this example also.

Public Class UCS
    <CommandMethod("ROTZ")> _
    Public Sub ShowHatchDialog()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = acDoc.Database
        Dim ucs As Matrix3d = acDoc.Editor.CurrentUserCoordinateSystem
        Dim cs As CoordinateSystem3d = ucs.CoordinateSystem3d
        Dim Rot As Matrix3d = Matrix3d.Rotation(0.785398163, cs.Zaxis, New Point3d(0, 0, 0))
        acDoc.Editor.CurrentUserCoordinateSystem = Rot
        acDoc.Editor.Regen()


        '' Start a transaction
        Using acTrans As Transaction = db.TransactionManager.StartTransaction()

            '' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)

            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            '' Create a line that starts at 5,5 and ends at 12,3
            Dim acLine As Line = New Line(New Point3d(5, 5, 0).TransformBy(Rot), _
                                          New Point3d(12, 3, 0).TransformBy(Rot))

            '' Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acLine)
            acTrans.AddNewlyCreatedDBObject(acLine, True)

            '' Save the new object to the database
            acTrans.Commit()
        End Using


    End Sub
End Class

 

Message 6 of 10
Giri_kani
in reply to: Ajilal.Vijayan

This is working fine for Line,Polyline,Solid...But for block insertion,it is not working..

 

I need to change the block based on current UCS with rotation point..that is i have rotation point..

 

Example:

BlockReference bref = new BlockReference(insertion_point.TransformBy(Rot), blkid);

 

bref.Rotation = DegToRad(270);

 

 

The Above code is not working correctly...

Message 7 of 10
Ajilal.Vijayan
in reply to: Giri_kani

Hi,

 

For block reference try the following.

 

       For block insertion point dont use TransformBy.

     


Then add.

      bref.TransformBy(Rot)

      bref.Rotation = DegToRad(270);

 

See the sample code inere.

Spoiler
Public Class UCS
    <CommandMethod("ROTZ")> _
    Public Sub ShowHatchDialog()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = acDoc.Database
        Dim ucs As Matrix3d = acDoc.Editor.CurrentUserCoordinateSystem
        Dim cs As CoordinateSystem3d = ucs.CoordinateSystem3d
        Dim Rot As Matrix3d = Matrix3d.Rotation(0.785398163, cs.Zaxis, New Point3d(0, 0, 0))
        acDoc.Editor.CurrentUserCoordinateSystem = Rot
        acDoc.Editor.Regen()


        Dim strBlockName As String = "MyBlock"
        Using tr As Transaction = db.TransactionManager.StartTransaction


            Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
            Dim btrMS As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForRead)
            If Not bt.Has(strBlockName) Then
                Exit Sub
            Else
                btrMS.UpgradeOpen()
            End If
            Dim btr As BlockTableRecord = bt(strBlockName).GetObject(OpenMode.ForRead)
            Dim bref As New BlockReference(New Point3d(5, 5, 0), btr.ObjectId)

            bref.TransformBy(Rot)
            bref.Rotation = 4.71238898
            btrMS.AppendEntity(bref)
            tr.AddNewlyCreatedDBObject(bref, True)

            tr.Commit()

        End Using
    End Sub
End Class

 

 

 

Message 8 of 10
Giri_kani
in reply to: Ajilal.Vijayan

This is working good..

 

Thank you very much...

Message 9 of 10
Giri_kani
in reply to: Giri_kani

 (command "_.AREA" "_E" (entlast))

 

 

I want to do the above mentioned process in .net....

 

Please guide me how to do?

Message 10 of 10
Ajilal.Vijayan
in reply to: Giri_kani

Hi,

There is a forum for .NET discussions.

It will be better to post the .net questions in there

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost