Jump to content

Adding Userdata to a selectionset


Chris85

Recommended Posts

Hi all,

 

i'm a beginner at Lisp programming .I started with the beginners Tutorials from Afralisp,  Kenny already has a LISP function in his tutorials that does what i want.

And already found some other LISP-Function that loops throught a selection set and prints the entity name (Thanks to Lee Mac).

 

There is a tutorual about Adding specific User data to an item.

https://www.afralisp.net/autolisp/tutorials/extended-entity-data-part-1.php

But i need to add these Userdata to all items in the model on a specific layer , the user data should be the actual modelname.

 

i modified the Script "entity List" Script  from Lee Mac, now it outputs only the entity names on my disired layer.

 

 

 (if (setq s (ssget "_X" '((8 . "desired Layer"))))
        (progn
            (setq i 0
                  n (sslength s)
            )
            (while (< i n)
                (setq e (ssname s i)
                      x (cdr (assoc -1 (entget e)))
                      ; new import
                      i (1+ i)
                )
                (print x)
            )
        )

 

I don't have a clue how to combine them. I tried some thing but they didn't work.

 

Kenny's script  uses

 

(setq oldlist (entget (car (entsel)))) ; i need to get this information within my loop. -> How to access the entity name from my code ?

(setq thedata '((-3 ("SU-DATA" (1000 . "Kenny is handsome") (1000 . "And intelligent")))))

....

 

 

In a further step i want to copy  a lot of blocks from a different models in a single one. All Items should have the Modelnamefrom their source modell as user data to find them in Navisworks simulate.

 

 

 

 

 

 

Link to comment
Share on other sites

Go back and look at part 1 & part 2 carefully study the add XDATA part to an entitity, you have the data but have not say carried out a entmod to add it to the entity.

Link to comment
Share on other sites

Hi Bigal,

 

Thanks for your reply.

I just a posted a part of the script, i didn't want to blow up the post too much.

Kenny's script uses two lists "oldlist" and "thedata" and combines them to the s single list(newdata).

The endmod function is finally assigning thedata to selected entity. This part is fine.

 

The script itselfs works for a single component which is selected by the user. I just posted the part where the single selection is mentioned.

I want to change the  entget (...) into something that works within the loop.

 

I tried to  use (entget e) like the script that shows the entitynames.. but got a wrong type error in this line.

(setq oldlist (entget e))

 

 

 

Link to comment
Share on other sites

8 hours ago, Chris85 said:

(setq oldlist (entget e))

@Chris85 This is correct for the loop in your original post, there must be something else incorrect.

 

I you look in the snippet from your original pose, (entget e) is already being used.

x (cdr (assoc -1 (entget e)));<---HERE

You have to put your modification code in the loop; I recommend:

(if (setq s (ssget "_X" '((8 . "desired Layer"))))
        (progn
            (setq i 0
                  n (sslength s)
            )
            (while (< i n)
                (setq e (ssname s i)
                      n (entget e);<---make a variable for the entity list
                      x (cdr (assoc -1 n));<---replace with the new variable
                      xd (assoc -3 n);<---get the xdata
                      i (1+ i);<--increase the counter for the next loop.
                )
                ; =====DO YOUR STUFF HERE====
                
                (print x)
            )
        )

 

Link to comment
Share on other sites

Try this:

(defun c:addXdata()
  (setq appName "comingFrom"
	data (getvar "dwgname"))
  (regapp appName)
  (setq e1 (car (entsel "select something on THAT layer"))
	ss (ssget "X" (list (assoc 8 (entget e1)))))
  (repeat (setq i (sslength ss))
    (addXd (ssname ss (setq i (1- i))) appName data))
  (setq ss nil)
  )

(defun c:showXdata()
  (setq en (car (entsel "\nselect object")))
  (setq appName "comingFrom")
  (setq el (entget en (list appName)))
  (princ (strcat "\tThat's a(n) " (cdr (assoc 0 el))))
  (setq xd (cadr (assoc -3 el)))
  (princ (strcat " " (car xd) ": " (cdadr xd)))
  (princ)
  )

(defun addXd(en appName data)
  (setq el (entget en)
	el (append el (list (list -3 (list appName (cons 1000 data))))))
  (entmod el)
  )

 

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