Polylines Joining For No Reason

Polylines Joining For No Reason

mgorecki
Collaborator Collaborator
1,020 Views
20 Replies
Message 1 of 21

Polylines Joining For No Reason

mgorecki
Collaborator
Collaborator

I have never run into this before, so I'm at a loss for why it's happening.  I'm using AutoCad 2018 Vanilla in Windows.

My code adds lwpolylines on a layer at a certain width (50.0).  It's like a grid with horizontal and vertical lwpolylines.

Then it turns off that layer and turns on, and sets, another layer.  It creates more lwpolylines with a different width (280) at the exact same coordinates.

When it's done running, the lwpolylines on the first layer are gone.  When I check the lwpolylines on the second layer, they have both widths.

This is a listing of one of the lwpolylines:

LWPOLYLINE Layer: "SOLDERMASK_BOTTOM"
Space: Model space
Handle = 1a21e
Closed
area 0.0000
perimeter 113600.0000

at point X=-35500.0000 Y=28400.0000 Z= 0.0000
starting width 50.0000
ending width 50.0000
at point X=-35500.0000 Y=-28400.0000 Z= 0.0000
starting width 280.0000
ending width 280.0000

 

This is the code used to create the lwpolylines:

(defun CreateLWPoly (plPntList plWidth openORclose)
 (entmake (append (list (cons 0 "LWPOLYLINE")
                        (cons 100 "AcDbEntity")
                        (cons 100 "AcDbPolyline")
                        (cons 90 (length plPntList))
                        (cons 70 openORclose) ;closed(1) or open(0)
                        (cons 43 plWidth)
                  )
                  (mapcar (function (lambda (p) (cons 10 p))) plPntList)
           )
 )
)

 

If anyone has an idea why this happens, I'd appreciate it if you let me know.  Thanks.

 

0 Likes
1,021 Views
20 Replies
Replies (20)
Message 2 of 21

john.uhden
Mentor
Mentor

@mgorecki 

The function looks good and functioned properly for me.

I think there maybe something else in the parent code that is causing the symptoms...

  Perhaps, outside the function, the variable feeding the plpntlist argument is being added to.

I have no idea how the first ones are being deleted, unless there is an (entdel (entlast)) after the function.

John F. Uhden

0 Likes
Message 3 of 21

mgorecki
Collaborator
Collaborator

Hi John, thanks for taking the time to look into this.  I think it could be the database gets so huge it freaks out.  I walked through the code and it worked properly, but if I just let it run to completion it merges the polylines.  So weird!

 

Thanks,

Mark

0 Likes
Message 4 of 21

stevor
Collaborator
Collaborator

'Merge' means what?
One large pline, or,
the ends of the intended pline changed
to coincide with other ends,
or what.

S
0 Likes
Message 5 of 21

mgorecki
Collaborator
Collaborator

It's strange, The first lwpolyline gets absorbed (if you will) into the second lwpolyline that gets created.  The coordinates are the same for both plines, each only had a starting point and an ending point.  It's just the first one disappears and the second now has 4 coordinates (instead of just the 2 it's supposed to have) and it also now has a starting width (the width of the original pline) and an ending width (from it's own created definition) instead of having their own individual widths.  The second one is now a "closed" polyline instead of being an "open" 2 point pline.

I even changed the code to freeze the first layer that the polylines were created on, but that didn't fix the issue.

I think what's happening is that the drawing is getting huge and because of that, it's freaking AutoCad out.

Since LiSP only works in the curent drawing and I need to create 2 drawings, I have one get created and then it gets saved.  Everything gets erased and even purged.  Then the second drawing gets created and saved.

I'm looking for a way to bring the size of the drawing back down, maybe an inconsequential save between the two drawings to a dummy drawing after the first erase and purge.  Who knows.  Back to testing..wheeeee!

0 Likes
Message 6 of 21

john.uhden
Mentor
Mentor

@mgorecki 

This may be just a shot in the dark, but there's something I recall from the dark ages...

Between entmakes add an (entmake)

John F. Uhden

0 Likes
Message 7 of 21

mgorecki
Collaborator
Collaborator

I've used the entmake for a number of objects, is there something else?  I know there is also entmakex, though I'm not sure what the difference is.

0 Likes
Message 8 of 21

john.uhden
Mentor
Mentor

@mgorecki 

I was just thinking that maybe AutoCAD stumbles over repeated consecutive calls to entmake something, so I thought maybe an (entmake) in between might separate the repetition.

Entmake returns the entity data the same as entget would return.

Entmakex returns just the ename of the created entity, which is handy in case you want to say add it to a selection set or use it in some command.

John F. Uhden

Message 9 of 21

Kent1Cooper
Consultant
Consultant

Does it do better if you include the Layer as an entry in the data list within each (entmake), rather than setting a current Layer before (entmake)ing each one?  Besides, it should be faster [gotta save those few milliseconds].

Kent Cooper, AIA
Message 10 of 21

mgorecki
Collaborator
Collaborator

Hi Kent,

Oh good grief, I don't know why that didn't occur to me to use that (slapping forhead).  I'll add that and see what happens.

Thanks.

0 Likes
Message 11 of 21

john.uhden
Mentor
Mentor

@mgorecki 

This has been bothering me.  I still think it's something outside of that function, or your AutoCAD has lost its marbles.

I tried the following, and it created 300 separate polylines , both open and closed separately, as would be expected.

(defun c:test ( / i pts width color @evenp e)
  (defun @evenp (n)(zerop (rem n 2)))
  (setq i 0)
  (princ (strcat "\ni = " (itoa i)))
  (repeat 100
    (setq i (1+ i) 
          width (if (@evenp i) 3.0 2.0)
          color i
    )
    (foreach pair '(((0 100)(0 200))((10 100)(10 200))((20 100)(20 200)))
      (setq e
        (entmakex
        (list (cons 0 "LWPOLYLINE")
              (cons 100 "AcDbEntity")
              (cons 100 "AcDbPolyline")
              (cons 90 2)
              (cons 70 0) ;closed(1) or open(0)
              (cons 43 Width)
              (cons 10 (car pair))
              (cons 10 (cadr pair))
              (cons 62 color)
        )
        )
      )  
      (princ (strcat "\ri = " (itoa i)))
    )
  )
  (princ)
)

So, I dunno.  Maybe I need to repeat 10,000 times?

John F. Uhden

0 Likes
Message 12 of 21

mgorecki
Collaborator
Collaborator

Hi John,

I think some of the issue is that there are thousands of other objects in the drawing.  I think the volume of object in the drawing is causing AutoCad to freak out.  I have a plan, which I'll try tomorrow or Monday and let you know if they clear up the issue.

Thanks again for looking into this problem.

0 Likes
Message 13 of 21

Sea-Haven
Mentor
Mentor

As John suggested had some problems entmaking a new block with 19 attributes, the solution was to use entmake for every item in particular the "Attdef" used a loop like Johns code to "entmake" each attribute.

 

The other thing I dont think it affects entmake is set osmode to say 0 to stop snapping.

 

Can you post an image of what your creating please. Just not sure what is end result.

0 Likes
Message 14 of 21

mgorecki
Collaborator
Collaborator

I thought I had mentioned it, but I didn't (so that's on me) I run the function that creates these lwpolylines twice.  Once for the first drawing, and again for the second drawing.  It's the same function, nothing changes.  It works correctly the first time.

Here is a pic of the overall second drawing and a closup of the issue.

pline_issue.png

There are 26227 entities in the drawing.  I'm going to try something else today.  I'll insert the polylines above the drawing and then move them down.  Then create the next set of plines above the drawing and move them down.  It's a pain, but I've got to try something. 😊

0 Likes
Message 15 of 21

mgorecki
Collaborator
Collaborator

Ok, creating the polylines above the rest of the drawing, then moving them down works.  I know it's cludgy and not how I wanted to do it, but hey, it works.  Thank you for all your suggestions and interest.

0 Likes
Message 16 of 21

john.uhden
Mentor
Mentor

@mgorecki 

I am not picturing this.

By up/down do you mean +Y/-Y or +Z/-Z?

John F. Uhden

0 Likes
Message 17 of 21

Sea-Haven
Mentor
Mentor

This is what I use  to make pline  , I would add (cons 8 layername)

(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))

Not sure if it helps,

 

Maybe try (entget (car (entsel '\nPick pline "))) look at the resulting entget order, is your entmake matching the order ? You dont have to have every dxf code. The 8 as suggested by Kent could be the clue.

 

It should not matter but maybe a zoom thrown in ? So can see the dwg and be in Model space.

 

Another stab in the dark something I am going to use is a VLA-ADD method, Vla-addpolyline. It is reported to be even faster than entmake. You will need to set the layer though as extra step. 

 

AddPolyline Method (afralisp.net)

 

((-1 . <Entity name: 642087d0>) (0 . "LWPOLYLINE") (5 . "3BD60") (330 . <Entity name: 642c1860>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (62 . 0) (370 . -1) (100 . "AcDbPolyline") (90 . 2) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 1583.0 1089.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 1638.xxx-xxxxxxxx 1087.xxx-xxxxxxxx) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0))

 

0 Likes
Message 18 of 21

john.uhden
Mentor
Mentor

@Sea-Haven 

Good idea.

I think what I have done in the past is to add a 2-point LWPoly and then (vlax-put Obj 'Coordinates flatlist)

where flatlist is made simply by (apply 'append 2dptlist), where 2dptlist looks like ((x1 y1)(x2 y2)...(xn yn)).

It's just a technique that's easier for me mentally.

John F. Uhden

0 Likes
Message 19 of 21

mgorecki
Collaborator
Collaborator

Hi John, I'm creating them +75000 in the Y.  Then after they're created I move them down.

0 Likes
Message 20 of 21

mgorecki
Collaborator
Collaborator

I changed my function after Kent suggested passing the layer name to the entmake.  This is what it looks like:

 

(defun CreateLWPoly (plPntList plWidth openORclose plLayer)
 (entmake (append (list (cons 0 "LWPOLYLINE")
                        (cons 100 "AcDbEntity")
                        (cons 100 "AcDbPolyline")
                        (cons 8 plLayer)
                        (cons 90 (length plPntList))
                        (cons 70 openORclose) ;closed(1) or open(0)
                        (cons 43 plWidth)
                  )
                  (mapcar (function (lambda (p) (cons 10 p))) plPntList)
           )
 )
)

 

 

Unfortunately, that did not correct the merging issue.

 

I started looking into the vla-addpolyline method.  I may be able to try it today.

0 Likes