.NET

Reply
Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 1 of 8 (244 Views)
Accepted Solution

Clone block with points

244 Views, 7 Replies
07-21-2013 11:00 PM

Hi,

I have a object which im cloning and moving along a path.I am finding the GeometricExtentsBestFit points of the block and plotting in the drawing.I want to clone the object with these points.Any idea on how to do this.Please help.

 

Dim bref As BlockReference = actran.GetObject(idsBox(0), OpenMode.ForWrite).

Dim BlockCloneNew As BlockReference = bref.Clone()

 

Dim bestFit AsExtents3d = bref.GeometryExtentsBestFit

 

Dim bestfitMin As Point3d = bestFit.MinPoint

Dim bestfitMax1 As Point3d = bestFit1.MaxPoint 

 

Thanks in advance

 

 

Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 2 of 8 (228 Views)

Re: Clone block with points

07-22-2013 12:47 AM in reply to: gulzar25

Hi,

Can someone suggest me on how to make the block and points as a single entity as mentioned above.

 

Thanks in advance

ADN Support Specialist
Balaji_Ram
Posts: 693
Registered: ‎03-21-2011
Message 3 of 8 (181 Views)

Re: Clone block with points

07-25-2013 02:32 AM in reply to: gulzar25

Hi,

 

Do you mean, you need to display the block reference clone and its extent points along the path ? 

In that case, using transient graphics to show them might help.

 

Here is a sample code that you can try. When prompted select a block reference and a polyline path. The block reference is cloned and displayed along the path at sampled points.

 

Public Class Test
    Implements IExtensionApplication

    Private _markers As DBObjectCollection = Nothing

    <CommandMethod("Test")> _
    Public Sub TestMethod()
        Dim activeDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = activeDoc.Database
        Dim ed As Editor = activeDoc.Editor

        Dim peo1 As New PromptEntityOptions("Select a block reference : ")
        peo1.SetRejectMessage("Not a block reference")
        peo1.AddAllowedClass(GetType(BlockReference), True)
        Dim per1 As PromptEntityResult = ed.GetEntity(peo1)
        If per1.Status <> PromptStatus.OK Then
            Return
        End If
        Dim brefId As ObjectId = per1.ObjectId

        Dim peo2 As New PromptEntityOptions("Select a polyline : ")
        peo2.SetRejectMessage("Not a polyline")
        peo2.AddAllowedClass(GetType(Polyline), True)
        Dim per2 As PromptEntityResult = ed.GetEntity(peo2)
        If per2.Status <> PromptStatus.OK Then
            Return
        End If
        Dim plineId As ObjectId = per2.ObjectId

        ClearTransientGraphics()
        _markers = New DBObjectCollection()

        Dim intCol As New IntegerCollection()

        Dim samplePoints As New Point3dCollection

        Using tr As Transaction = db.TransactionManager.StartTransaction()
            Dim bref As BlockReference = TryCast(tr.GetObject(brefId, OpenMode.ForRead), BlockReference)
            Dim pline As Polyline = TryCast(tr.GetObject(plineId, OpenMode.ForRead), Polyline)

            If pline IsNot Nothing Then
                Dim segCount As Integer = pline.NumberOfVertices
                For cnt As Integer = 0 To segCount - 1
                    Dim vertexPt As Point3d = pline.GetPoint3dAt(cnt)
                    Dim type As SegmentType = pline.GetSegmentType(cnt)

                    Select Case type
                        Case SegmentType.Arc

                            Dim arc2d As CircularArc2d = pline.GetArcSegment2dAt(cnt)
                            Dim samplePts1 As Point2d() = arc2d.GetSamplePoints(5)
                            For Each pt2d As Point2d In samplePts1
                                samplePoints.Add(New Point3d(pt2d.X, pt2d.Y, 0.0))
                            Next
                            Exit Select

                        Case SegmentType.Line

                            Dim line2d As LineSegment2d = pline.GetLineSegment2dAt(cnt)
                            Dim samplePts2 As Point2d() = line2d.GetSamplePoints(5)
                            For Each pt2d As Point2d In samplePts2
                                samplePoints.Add(New Point3d(pt2d.X, pt2d.Y, 0.0))
                            Next
                            Exit Select
                    End Select
                Next
            End If

            For Each pt As Point3d In samplePoints
                Dim marker1 As BlockReference
                marker1 = bref.Clone()
                marker1.Position = pt
                Autodesk.AutoCAD.GraphicsInterface.TransientManager.CurrentTransientManager.AddTransient(marker1, Autodesk.AutoCAD.GraphicsInterface.TransientDrawingMode.Highlight, 128, intCol)
                _markers.Add(marker1)

                Dim exts As Extents3d
                exts = marker1.GeometryExtentsBestFit()

                Dim marker2 As DBObject
                'marker2 = New DBPoint(exts.MinPoint)
                marker2 = New Circle(exts.MinPoint, Vector3d.ZAxis, 0.1)
                Autodesk.AutoCAD.GraphicsInterface.TransientManager.CurrentTransientManager.AddTransient(marker2, Autodesk.AutoCAD.GraphicsInterface.TransientDrawingMode.Highlight, 128, intCol)
                _markers.Add(marker2)

                Dim marker3 As DBObject
                'marker3 = New DBPoint(exts.MaxPoint)
                marker3 = New Circle(exts.MaxPoint, Vector3d.ZAxis, 0.1)
                Autodesk.AutoCAD.GraphicsInterface.TransientManager.CurrentTransientManager.AddTransient(marker3, Autodesk.AutoCAD.GraphicsInterface.TransientDrawingMode.Highlight, 128, intCol)
                _markers.Add(marker3)
            Next

            tr.Commit()
        End Using
    End Sub

    Private Sub IExtensionApplication_Initialize() Implements IExtensionApplication.Initialize
    End Sub

    Private Sub ClearTransientGraphics()
        Dim intCol As New IntegerCollection()
        If _markers IsNot Nothing Then
            For Each marker As DBObject In _markers
                Autodesk.AutoCAD.GraphicsInterface.TransientManager.CurrentTransientManager.EraseTransient(marker, intCol)
                marker.Dispose()
            Next
        End If
    End Sub

    Private Sub IExtensionApplication_Terminate() Implements IExtensionApplication.Terminate
        ClearTransientGraphics()
    End Sub
End Class

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 4 of 8 (175 Views)

Re: Clone block with points

07-25-2013 03:21 AM in reply to: Balaji_Ram
Hi Balaji,
Thanks a lot for the reply.I want to display block and its extent points along a path.But this should be placed with respect to 2 points on the block.So when i move the block at certain intervals it is sometimes at an angle wrt the path, in such scenarios the geometric extents is not coming correctly.So i want to calculate the geometricextents initially and treat points and block as one entity and clone.Is this possible.I hope i am clear.

Thanks in advance
ADN Support Specialist
Balaji_Ram
Posts: 693
Registered: ‎03-21-2011
Message 5 of 8 (172 Views)

Re: Clone block with points

07-25-2013 04:34 AM in reply to: gulzar25

Sorry. I do not get the exact picture. Can you please share a drawing or a screenshot of what you are trying to do ?

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 6 of 8 (171 Views)

Re: Clone block with points

07-25-2013 04:42 AM in reply to: Balaji_Ram
Hi ,
I just want to know if for a block I get the geometricextents and plot the points.Is there any function or api to convert this block and set of points as one entity.I want to clone this points and block as a single entity.

Thanks
Gulzar
*Expert Elite*
_gile
Posts: 2,084
Registered: ‎04-29-2006
Message 7 of 8 (159 Views)

Re: Clone block with points

07-25-2013 07:39 AM in reply to: gulzar25

Hi,

 

The Point3d structure do not inherit from Entity neither from DBObject. A Point3d instance is only a geomeric object and cannot be added to an entity or cloned as DBObject instances.

 

You can create DBPoint instances, which are entities, from the Point3d and create a new BlockTableRecord which contains the source block reference and the DBPoint instances, then, insert it and clone it.


But you may also get the extents of the cloned object...

 

Or if you want to embed the extents (coordinates) of the source object to the cloned one(s), you can store them in the source block reference as attributes, xdata or extension dictionary xrecords before doing the cloning operation.

Gilles Chanteau
Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 8 of 8 (146 Views)

Re: Clone block with points

07-25-2013 09:05 AM in reply to: gulzar25
Hi,
I am not using the geometricextents function after clone is because in somecases i also do rotation on the block and when i try to retrieve the geometricextents it is giving me the extents for the block position before rotation.So i thought ill make point and block as single entity and clone.How do i make the points as attributes?
thanks
Gulzar
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.