AcadLWPolyline and AcDbPolyline

AcadLWPolyline and AcDbPolyline

Delforge
Contributor Contributor
3,153 Views
9 Replies
Message 1 of 10

AcadLWPolyline and AcDbPolyline

Delforge
Contributor
Contributor

Hello,

I have a problem with AcadLWPolyline and AcDbPolyline.

I create a lightweight polyline in model space, then i want to work with this polyline.

It's work if i work dirrectly with this polyline but it doesn't work if i recovers this polyline.

 

This following code work but not if i change 'plineObj = oEntite in plineObj = oEntite

I have the impression that AcadLWPolyline and AcDbPolyline is not the same thing for autocad but it is the same polyline !
 
What to do ?
 
Thanks for your help.
 
Regards,
Quentin
 
Sub Example_GetBulge()
    ' This example creates a lightweight polyline in model space.
    ' It then finds and changes the bulge for a given segment.
    
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    Dim i As Integer

    ' Define the 2D polyline points
    points(0) = 0: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 1
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 3
    points(10) = 2: points(11) = 6
        
    ' Create a lightweight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    ZoomAll

    ' Change the bulge of the third segment
    plineObj.SetBulge 3, 0.5
    plineObj.Update

For Each oEntite In ThisDrawing.ModelSpace 'on parcourt tous les éléments dans le dessin (hors xref)
    If oEntite.ObjectName = "AcDbPolyline" And oEntite.Layer = "0" Then
    'plineObj = oEntite
    longeur_poly = Round(UBound(plineObj.Coordinates) / 2, 0) - 1
    i = 0
    P1 = plineObj.Coordinate(0)
    While i < longeur_poly
        rayon = Sqr((CenterPt(plineObj, i)(0) - plineObj.Coordinate(i)(0)) ^ 2 + (CenterPt(plineObj, i)(1) - plineObj.Coordinate(i)(1)) ^ 2)
        MsgBox (rayon)
        i = i + 1
    Wend
    End If
Next

End Sub

Public Function CenterPt(PolyLin As AcadLWPolyline, Optional Vertex As Integer) As Variant
Dim PolyPts As Variant
Dim PolySp(0 To 2) As Double
Dim PolyEp(0 To 2) As Double
Dim Lin1 As AcadLine
Dim Ang As Double
Dim IsoAng As Double
Dim Radius As Double
Dim ClockWise As Boolean
Dim RadAng As Double
Dim Bulg As Double
If Vertex = Empty Then Vertex = 0
Bulg = PolyLin.GetBulge(Vertex)
PolyPts = PolyLin.Coordinates
PolySp(0) = PolyPts(Vertex * 2 + 0): PolySp(1) = PolyPts(Vertex * 2 + 1)
PolyEp(0) = PolyPts(Vertex * 2 + 2): PolyEp(1) = PolyPts(Vertex * 2 + 3)
Set Lin1 = ThisDrawing.ModelSpace.AddLine(PolySp, PolyEp)
Ang = Atn(Bulg) * 4
IsoAng = Ang / 3.141592654 * 180
If IsoAng < 0 Then
IsoAng = (IsoAng + 180) / 2
ClockWise = True
Else
IsoAng = (180 - IsoAng) / 2
End If
IsoAng = IsoAng / 180 * 3.141592654
If ClockWise Then
RadAng = Lin1.Angle + IsoAng + 3.141592654
Else
RadAng = Lin1.Angle - IsoAng + 3.141592654
End If
Radius = (Lin1.Length / 2) / Cos(IsoAng)
CenterPt = ThisDrawing.Utility.PolarPoint(PolyEp, RadAng, Radius)

Lin1.Delete
End Function
0 Likes
Accepted solutions (1)
3,154 Views
9 Replies
Replies (9)
Message 2 of 10

-didier-
Advisor
Advisor

Coucou Hello

 

I think you should look at the value of the plinetype variable, it should be 2

 

Amicalement Friendly

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 3 of 10

cadffm
Consultant
Consultant

Plinetype? Plinetype is for PLINE command, nothing more, or?

But Polyline and LwPolyline are two diffwrent objecttype like circle and line,

differenz properties/ property names and available settings.

Sebastian

0 Likes
Message 4 of 10

_gile
Consultant
Consultant

hi,

 

First, you should have posted in the VB forum (or in the french AutoCAD forum).

 

Why do you iterate the whole model space to search the entity you created in the same Sub instead of just using the plineObj variable?

 

Anyway, AcDbPolyline is the ObjectARX class name (ObjectName  COM property) for the COM AcadLWPolyline COM type.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 10

-didier-
Advisor
Advisor

Coucou Hello

 

Plinetype is really about the polyline...

extract from the help :

PLINETYPE controls both the creation of new polylines with the PLINE command and the conversion of existing polylines in drawings from previous releases.

 

Amicalement friendly

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 6 of 10

cadffm
Consultant
Consultant

@-didier- 

Sure, i never said other things, but this is for native 'Autocad commands', nothing to do with programming via API, instead you are using simple (send)command Functions to controle 'native AutoCAD commands', OR?

 

 

Sebastian

0 Likes
Message 7 of 10

Delforge
Contributor
Contributor

 

Thanks,

 

plinetype variable, is 2 but no difference with 0 or 1.

 

The problem can come only from

Dim plineObj As AcadLWPolyline

or

If oEntite.ObjectName = "AcDbPolyline".

 

I have try with AcadPolyline but no succes

 

0 Likes
Message 8 of 10

SeeMSixty7
Advisor
Advisor

There is a significant difference between an LWPolyline and a Polyline.

 

The lightweight Poly has a different structure in than AutoCAD Database than the Polyline

 

The traditional polyline has a head entity and then followed by a sequence of additional vertex entities. Visual LISP  object access seems transparent on accessing the two ent types the same, I assume VB does as well, but the reality is there are separate entities on an actual polyline type, that would have to be considered if you are trying to actually step down into the sub entities and manipulate them. 

 

Since you are creating as a LWpoly then stick with that and avoid the polyline type all together.

 

PLINETYPE controls what method autocad creates plines as using the pline command. 3DPOLY always creates a Polyline entity as the LW can't handle 3D points. 

 

Hope that helps in some way.

 

0 Likes
Message 9 of 10

_gile
Consultant
Consultant
Accepted solution

@Delforge wrote:

The problem can come only from

Dim plineObj As AcadLWPolyline

or

If oEntite.ObjectName = "AcDbPolyline".


Nope, the ObjectName property returns the ObjectARX class name.

And the ObjectARX class name for the AcadLWPolyline COM is "AcDbPolyline".

 

image.png

 

I'm not very cumfortable with VB(A) but it seems to me you can simply use the 'oEntite' variable:

 

 

Sub Example_GetBulge()
    ' This example creates a lightweight polyline in model space.
    ' It then finds and changes the bulge for a given segment.
    
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 11) As Double
    Dim i As Integer

    ' Define the 2D polyline points
    points(0) = 0: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 1
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 3
    points(10) = 2: points(11) = 6
        
    ' Create a lightweight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    ZoomAll

    ' Change the bulge of the third segment
    plineObj.SetBulge 3, 0.5
    plineObj.Update

For Each oEntite In ThisDrawing.ModelSpace 'on parcourt tous les éléments dans le dessin (hors xref)
    If oEntite.ObjectName = "AcDbPolyline" And oEntite.Layer = "0" Then
	longeur_poly = Round(UBound(oEntite.Coordinates) / 2, 0) - 1
	i = 0
	P1 = oEntite.Coordinate(0)
	While i < longeur_poly
	    rayon = Sqr((CenterPt(oEntite, i)(0) - oEntite.Coordinate(i)(0)) ^ 2 + (CenterPt(oEntite, i)(1) - oEntite.Coordinate(i)(1)) ^ 2)
	    MsgBox (rayon)
	    i = i + 1
	Wend
    End If
Next

End Sub

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 10

Delforge
Contributor
Contributor

Thanks, it was the solution !!!

0 Likes