Jump to content

Recommended Posts

Posted

I'm looking for a way that I can trim some information off of a variable I have set. I'm setting the layer name of an entity to a variable by getting its layer name from the DXF list so it reads like this: "(8 . "G-GENL-TEXT")" and I'm looking to trim that down to just: "G-GENL-TEXT" so I can use it to set my current layer.

 

Thanks.

Posted

The answer is CDR function - the dotted pairs behave a little different than the lists.

(cdr '(8 . "G-GENL-TEXT"))

The reason is to allow you to extract the data from associated lists by preserving their form - atom or list:

(cdr '(10 1.0 2.0 3.0))

Posted
I'm looking for a way that I can trim some information off of a variable I have set. I'm setting the layer name of an entity to a variable by getting its layer name from the DXF list so it reads like this: "(8 . "G-GENL-TEXT")" and I'm looking to trim that down to just: "G-GENL-TEXT" so I can use it to set my current layer.

 

Consider:

(defun c:FOO (/ eName)
 (if (setq eName (car (entsel "\nSelect entity to set layer current: ")))
   (setvar 'clayer (cdr (assoc 8 (entget eName))))
 )
 (princ)
)

 

... Or simply use the LAYMCUR Command.

Posted

......I can't believe I didn't think of using the cdr function for that.

 

Blackbox - I use the Laycur command later on in the code but I wanted to switch over to using setvar instead so the code is more automatide unstead of prompting the user to make a bunch of different selections. Thanks for the advice though.

Posted
......I can't believe I didn't think of using the cdr function for that.

 

Blackbox - I use the Laycur command later on in the code but I wanted to switch over to using setvar instead so the code is more automatide unstead of prompting the user to make a bunch of different selections. Thanks for the advice though.

 

No worries; everyone needs a little reminder now and then.

 

I only use Commands when advantageous... I usually prefer the Setvar method myself as well.

 

Cheers :beer:

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