.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block Insertion along Closed Polyline

1 REPLY 1
Reply
Message 1 of 2
dmleves49
306 Views, 1 Reply

Block Insertion along Closed Polyline

                I've been using the admittedly pieced together code in order to insert border blocks around a closed polyline. Yhe problem I'm having is that when the Block angle is say "zero"  the block is inserted the same way both on top and below the polyline. Since the blocks surround the polyline the blocks on the downside should have an additional 180 degree rotation. Does anyone know how to deduct that the portion of the polyline is in a certain quadrant and adjust the insertion angle as necc? I 'm not sure thats even the best approach. Any suggestions appreciated.

 

 

   Dim pso As PromptStringOptions = New PromptStringOptions("Enter name of block to create reference: ")
                    Dim pr As PromptResult = myEd.GetString(pso)
                    Dim blkName As String = pr.StringResult
                    'If (!bt.Has(blkName)) Then
                    '        {
                    '            ed.WriteMessage ("Current Database does not contain a block of that name!");
                    '            return;
                    '        }
                    Dim bt As BlockTable = Trans.GetObject(db.BlockTableId, OpenMode.ForRead)

                    Dim btr As BlockTableRecord = Trans.GetObject(bt(blkName), OpenMode.ForRead)
                    Dim pdo As PromptDistanceOptions = New PromptDistanceOptions("Indicate distance along path: ")

                    pdo.AllowArbitraryInput = False
                    Dim pdr As PromptDoubleResult = myEd.GetDistance(pdo)
                    '        if (pdr.Status != PromptStatus.OK) return;

                    Dim leng As Double = plin1.Length

                    Dim iTop As Int16 = Decimal.Divide(leng, pdr.Value) - 2

                    Dim currSpace As BlockTableRecord = Trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
                    plin2.Layer = "Hatch"
                    For i = 1 To iTop
                        Dim p3d As Point3d = crv.GetPointAtDist(pdr.Value * i)
                        Dim v3d As Vector3d = crv.GetFirstDerivative(p3d)
                        Dim ang As Double = Math.Atan(v3d.Y / v3d.X)
                        Debug.Print(ang.ToString)


                        'If ang <= 0 And i < Decimal.Divide(iTop, 2.0) Then
                        '    ang = ang + PI ' + Decimal.Divide(PI, 2.0)
                        'ElseIf ang >= 0 And i > Decimal.Divide(iTop, 2.0) Then
                        '    ang = ang + PI
                        'End If

                        Dim insert As BlockReference = New BlockReference(p3d, btr.ObjectId)
                        insert.Rotation = ang
                        currSpace.AppendEntity(insert)
                        insert.SetDatabaseDefaults()
                        Trans.AddNewlyCreatedDBObject(insert, True)

                    Next i
      

1 REPLY 1
Message 2 of 2
cadMeUp
in reply to: dmleves49

Assuming the curve/polyline is on the world plane, you can find the angle of a vector on a plane:

 

Dim testVec As Vector3d = New Vector3d(-1, -1, 1)
Dim worldPlane As Plane = New Plane(Point3d.Origin, Vector3d.ZAxis)
Dim radAng As Double = testVec.AngleOnPlane(worldPlane)

 

radAng would equal 3.92699081698724 radians or 225 degrees

 

Hope this helps...

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost