Jump to content

The new layer as a namespace.


Alex_Miller

Recommended Posts

I have a theoretical question.

When I create a single object, I can use it and then delete it.

(setq object (entlast))
(entdel object)


If there are the several objects I can create the set.
For work I use a new layer, then delete it.
I'm not sure if I am doing the right thing.
How do you control multiple objects at the same time?

Link to comment
Share on other sites

Suppose I have a few lines. I want to create a set.
But there are still other lines in the project.
I want form a set of only the correct lines.
There are many more steps. Objects are created and deleted during work.
Then I create a new layer for my objects. 

Is it possible to do differently, not to create a layer?

Link to comment
Share on other sites

;;; the excess lines of project, being on layer "0"
((lambda (/ c pt1 pt2)
  (setq c 20
        pt1 (list c 0)
        pt2 (list c 10))
  (repeat 5 
    (command "_.line" pt1 pt2 "")
    (setq c (+ 10 c)
        pt1 (list c 0)
        pt2 (list c 10))
  )))

;;; my objects
(command "'_.layer" "_new" "new.layer" "_s" "new.layer" "")
(command "_.rectangle" "0,0" "10,10")
(setq object (entlast))
(command "_.explode" object)
(setq lines (ssget "_X" '((0 . "LINE") (8 . "new.layer"))))

  do something

((lambda (/ c)
  (setq c 0)
  (repeat (sslength lines)
    (entdel (ssname lines c))
    (setq c (+ 1 c)))))

 

Link to comment
Share on other sites

With vanilla LISP, you can obtain the set using entlast / entnext functions (without having the need to group them in a separate layer) :

(setq ListOfLineEnames
  (
    (lambda ( / object tmp eL )
      (command "_.rectangle" "0,0" "10,10")
      (command "_.explode" (setq object (entlast)))
      (setq tmp object)
      (while (setq tmp (entnext tmp))
        (setq eL (cons tmp eL))
      )
      eL
    )
  )
)

(foreach line ListOfLineEnames
  (entdel line)
  ; or do whatever you want here
)

Also you can create these objects "programatically", meaning wihtout any command calls. So you can store them instantly while creating.

  • Like 1
Link to comment
Share on other sites

4 minutes ago, Alex_Miller said:

 Grrr Thank you! I will improve my skills. :)

 

No problem, in addition check out Lee's entmake functions, where you supply the arguments and the entity name is returned, so you can store it or manipulate it further.

Also the basic structures in LISP are lists and atoms, so its acceptable to work with a list of enames, rather than a selection set.

  • Like 1
Link to comment
Share on other sites

You can also use SSADD which adds objects to a selection set. If you want to save the 4 lines of the rectang individually.

 

I would suggest you write a little defun that does just that makes 4 lines from the two corner points if you use ssadd then the lines would be 4 items in the selection set and you can get at each one for further action.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...