The result of entlast function is not complete

The result of entlast function is not complete

326047736
Contributor Contributor
576 Views
6 Replies
Message 1 of 7

The result of entlast function is not complete

326047736
Contributor
Contributor

Hello everyone.

 

I created a boundary that has two polylines by the AutoLISP command function. And then trying to use entlast function to get all the polylines of this boundary, but can only get one. What should I do next?

 

demo.gif

 

Any reply might be helpful, thanks!

0 Likes
Accepted solutions (2)
577 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor
Accepted solution

@326047736 wrote:

Hello everyone.

 

I created a boundary that has two polylines by the AutoLISP command function. And then trying to use entlast function to get all the polylines of this boundary, but can only get one. What should I do next?


Function ENTLAST will select only last created entity. Check function SSGET.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Save the last entity BEFORE you apply your function.

Then get all (entnext) until you reach the end of the database.

Message 4 of 7

326047736
Contributor
Contributor

Thanks, @hak_vz, so the code below might be work in some cases:

 

 

(defun c:test (/ boundaryPnt layername oldlayer flag ss)
  (setq layername "templayer")
  (setq oldlayer (getvar "CLAYER")) ; Save origin layer name
  (setq flag (tblsearch "LAYER" layername)) ; Looking for existing
  (if (null flag) (progn (command "_.-layer" "m" layername ""))) ; Creat new layer if not exist
  (setvar "CLAYER" layername) ; Change current layer to <layername>
  (setq boundaryPnt (getpoint "\nGet point"))
  (command "_.-boundary" "A" "O" "P" "" boundaryPnt "")
  (setq ss (ssget "_X" (list (cons 8 layername))))
  (command "_.move" ss)
  ;; Other code

  (setvar "CLAYER" oldlayer) ; Change back to the origin layer to layername
  ;; (command "_.-laydel" "_N" layername "" "_Y") ; Delete temp layer and all the objects in the layer(if you want)
)

 

 

Ref: 

creating-layer-and-styles-with-autolisp

ssget 

0 Likes
Message 5 of 7

326047736
Contributor
Contributor

Thanks, @ВeekeeCZ, this is a clearer idea and be easier to code:

 

(defun c:test (/ ss lastBefore)
  (setq lastBefore (entlast) ss (ssadd))
  (setq boundaryPnt (getpoint "\nGet point"))
  (command "_.-boundary" "A" "O" "P" "" boundaryPnt "")
  (while (setq lastBefore (entnext lastBefore)) 
    (setq ss (ssadd lastBefore ss))
  )
  ;; Other code
  (command "_.move" ss)
)
Message 6 of 7

hak_vz
Advisor
Advisor

@326047736  Yes it will work. Try to come up with your code, I'll look later today to help you finish it. Currently at work so have no time.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 7

326047736
Contributor
Contributor
You might have found some issues with the origin code too. So I updated the code and it works for me now. But it would be better to add some error handling code.

Thanks again for taking the time to answer the question. 👋
0 Likes