Author Topic: Block Rotation  (Read 168 times)

0 Members and 1 Guest are viewing this topic.

sigster

  • Newt
  • Posts: 26
Block Rotation
« on: April 12, 2022, 10:55:47 AM »
Hi

Any ide how I can fix this
90 will be 270 and 270 will be 90

      br.Rotation = DegToRad(270)    this turn the block arrow down but I need to have the arrow upp



Code: [Select]

   <CommandMethod("BLOCKINS1")>
        Public Sub blocktry()
            ' Insert.Enabled = False
            Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
            Dim ed As Editor = acDoc.Editor

         
            Using lockmedoc As DocumentLock = acDoc.LockDocument()
                Dim blockName As String = "BLOCKNAME"
                Dim blockQualifiedFileName As String = "PATH TO BLOCK" & "..dwg"

                Using tr As Transaction = db.TransactionManager.StartTransaction()

                    Try
                        Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)

                        If Not bt.Has(blockName) Then
                            Dim tmpDb As Database = New Database(False, True)
                            tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, True, "")

                            Try
                                db.Insert(blockName, tmpDb, True)
                            Catch
                            End Try
                        End If

                        Dim ppr As PromptPointResult = ed.GetPoint(vbLf & "Specify insertion point: ")
                        'If ppr.Status = PromptStatus.Cancel Then 'Insert.Enabled = True
                        If ppr.Status <> PromptStatus.OK Then Return
                        Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                        Dim br As BlockReference = New BlockReference(Point3d.Origin, bt(blockName))
                        br.ScaleFactors = New Scale3d(1)


                        br.Rotation = DegToRad(30)

                        br.TransformBy(Matrix3d.Displacement(ppr.Value - Point3d.Origin).PreMultiplyBy(ed.CurrentUserCoordinateSystem))
                        btr.AppendEntity(br)
                        tr.AddNewlyCreatedDBObject(br, True)
                        ed.WriteMessage(vbLf & br.Name & " Inserted")
                        ' Insert.Enabled = True
                    Catch exx As Autodesk.AutoCAD.Runtime.Exception
                        ed.WriteMessage(vbLf & exx.ToString())
                        'Insert.Enabled = True
                    End Try

                    tr.Commit()
                    tr.Dispose()
                End Using
            End Using
        End Sub


    Public Function DegToRad(angle As Double)
            'convert degrees to radians
            DegToRad = ((angle / 180) * Math.PI)
        End Function

        Public Function RadToDeg(angle As Double)
            'convert radians to degrees
            RadToDeg = ((angle * 180) / Math.PI)
        End Function


Atook

  • Swamp Rat
  • Posts: 994
  • AKA Tim
Re: Block Rotation
« Reply #1 on: April 12, 2022, 11:23:52 AM »
Use a negative rotation?

gile

  • Water Moccasin
  • Posts: 2379
  • Marseille, France
Re: Block Rotation
« Reply #2 on: April 12, 2022, 11:47:22 AM »
Hi,
Internally AutoCAD always uses counter-clockwise radians.

Code: [Select]
      PI * 0.5

PI       >       0.0

      PI * 1.5
Speaking English as a French Frog