Jump to content

Changing 2 entities at once in entity list.


Dayananda

Recommended Posts

(entmod (subst (cons 10 LeftEnd1)(assoc 10 entlist) entlist))
(entmod (subst (cons 11 LeftEnd2)(assoc 11 entlist) entlist))

When I apply  above codec to a vertical line it does not work properly. How can I add above codes to a one code.

Link to comment
Share on other sites

Make yourself a function

(defun dy:entmod (code val lst) (entmod (subst (cons code val) (assoc code lst) lst)))

then


 

(setq e_lst (entget ent))

(foreach x (list (list 10 leftEnd1) (list 11 leftend2)) (dy:entmod (car x) (cadr x) e_lst))

 

  • Like 1
Link to comment
Share on other sites

The reason that your original code does not work as expected is because the second entmod expression is still operating on the original DXF list bound to the variable entlist and therefore you will receive a result whereby DXF group 11 has the new value, and DXF group 10 has reverted back to its original value.

 

There are many ways around this, but the easiest & most readable might be:

(setq entlist (subst (cons 10 LeftEnd1) (assoc 10 entlist) entlist)
      entlist (subst (cons 11 LeftEnd2) (assoc 11 entlist) entlist)
)
(entmod entlist)

Alternatively, you can nest the subst expressions, e.g.:

(entmod (subst (cons 11 LeftEnd2) (assoc 11 entlist) (subst (cons 10 LeftEnd1) (assoc 10 entlist) entlist)))

 

Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

3 hours ago, ronjonp said:

This should work too:


(entmod (append entlist (list (cons 10 leftend1) (cons 11 leftend2))))

 

 

Just be aware that that method only works with certain entities, and won't work with entities which require subclass markers in the DXF data.

 

  • 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...