Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Adding Second Atribute to Inserted Block

Anonymous

Adding Second Atribute to Inserted Block

Anonymous
Not applicable

I have a LISP that someone wrote on here a little while ago (thanks again!) that would allow a user to import a .csv file, and from that file take a point name, then the x,y,z coordinates and place the block in automatically.

I need to modify that lisp and add a second attribute name.

I tried adding a second ATT expression but it did not seem to accept it.

Any hints on where and how a couple of lines should be added (see attached)?

0 Likes
Reply
Accepted solutions (1)
1,362 Views
12 Replies
Replies (12)

pbejse
Mentor
Mentor

@Anonymous wrote:

I tried adding a second ATT expression but it did not seem to accept it.

Any hints on where and how a couple of lines should be added (see attached)?


If you know the TAG names you can do it this way

 

(defun c:I-MW (/ fn fp lst l)
  (setq fn (getfiled "Select CSV file" "" "csv" 4))
  (setq	fp  (open fn "r")
	lst '()
  ) ;_ end of setq
  (while (setq l (read-line fp))
    (setq lst (cons l lst))
  ) ;_ end of while
  (close fp)
  (setq VAL (getvar "attreq"))
  (command "attreq" 0)
  (foreach Row lst
    (while (if (setq n (vl-string-search "," Row 0))
		     (setq Row (vl-string-subst " " "," Row))
		   ) ;_ end of if
    ) ;_ end of while
    (setq Row (read (strcat "(" Row ")")))
    (setq ATT1 (vl-symbol-name (nth 0 Row)))
    (setq X (nth 1 Row))
    (setq Y (nth 2 Row))
    (setq Z (nth 3 Row))
    (setq PT1 (list X Y Z))
    (command "insert" "monitoring_well" PT1 "1" "" "")
    (setq bl (entlast))
    	(setpropertyvalue bl "ATT1" ATT1)
    	(setpropertyvalue bl "ATT2" "AnotherValue")
  ) ;_ end of foreach
  (command "attreq" VAL)
)

 

0 Likes

cadffm
Consultant
Consultant

To show how it works in the way your program works now,

look at this (pbejse answer is a good one, but i like also to show this / for a better understanding of your original code).

 

 

Original
(defun c:I-MW ( / fn fp lst l)
(setq fn (getfiled "Select CSV file" "" "csv" 4))
(setq fp (open fn "r") lst '())
(while (setq l (read-line fp))
(setq lst (cons l lst))
)
(close fp)
(setq VAL (getvar "attreq")) 
(command "attreq" 0) ;; <-- disable the question about attributvalues
(foreach Row lst
(while (if (setq n (vl-string-search "," Row 0))
(setq Row (vl-string-subst " " "," Row))
)
)
(setq Row (read (strcat "(" Row ")")))
(setq ATT1 (vl-symbol-name (nth 0 Row)))
(setq X (nth 1 Row))
(setq Y (nth 2 Row))
(setq Z (nth 3 Row))
(setq PT1 (list X Y Z))
(command "insert" "monitoring_well" PT1 "1" "" "")
(setq b1 (entget (entnext (entlast)))) ; <-- take the blockreference
(setq ff1(assoc 1 b1))
(setq xx1 (cons 1 ATT1))
(entmod(subst xx1 ff1 b1))
)
(command "attreq" VAL)
)


Var1
(defun c:I-MW ( / fn fp lst l VAL DAL n row x y z ATT1 PT1)
(setq fn (getfiled "Select CSV file" "" "csv" 4))
(setq fp (open fn "r") lst '())
(while (setq l (read-line fp))
(setq lst (cons l lst))
)
(close fp)
(setq VAL (getvar "attreq")) 
(setq DAL (getvar "attdia")) ;; <--Thats also good for your original code! Att dialogwindow, or not..
(command "attreq" 1) ;; <-- enable the question about attributvalues
(command "attdia" 0) ;; <-- disable the question about attributvalues
(foreach Row lst
(while (if (setq n (vl-string-search "," Row 0))
(setq Row (vl-string-subst " " "," Row))
)
)
(and
(setq Row (read (strcat "(" Row ")")))
(setq ATT1 (vl-symbol-name (nth 0 Row)))
(setq X (nth 1 Row))
(setq Y (nth 2 Row))
(setq Z (nth 3 Row))
(setq PT1 (list X Y Z))
(command "insert" "monitoring_well" PT1 "1" "" "" ATT1)
);_and
)
(command "attreq" VAL "attdia" DAL)
)

;; Start the command -INSERT to see whats going on inside your "(command ..)"

 

 

Sebastian

0 Likes

pbejse
Mentor
Mentor

@cadffm wrote:

To show how it works in the way your program works now,

look at this

...
(command "attreq" 1) ;; <-- enable the question about attributvalues
(command "attdia" 0) ;; <-- disable the question about attributvalues
...

 


Agreed, thats makes a lot more sense 👍

...
(command "insert" "monitoring_well" PT1 "1" "" "" ATT1 ATT2 ATT3 ...) ;< as many as you need
...)

 

0 Likes

cadffm
Consultant
Consultant

Oups

 

(command "attreq" 1) ;; <-- enable the question about attributvalues
(command "attdia" 0) ;; <-- disable the question about attributvalues
(command "attdia" 0) ;; <-- change the dialog window version to the commandline version (when Acad ask for  attributvalues)

Sebastian

0 Likes

Anonymous
Not applicable

Thanks for your reply.

 

One item I didn't ask about is what column within the .csv file would the Lisp use for the second attribute? How is that specified?

I haven't tried your changes yet but will shortly pending the question above.

 

0 Likes

Anonymous
Not applicable

Are you suggesting everything under Var1 should be the new code rather than just change for the comments in the original code?

0 Likes

hak_vz
Advisor
Advisor

In code you have this:

 

 

(setq Row (read (strcat "(" Row ")")))
(setq ATT1 (vl-symbol-name (nth 0 Row)))
(setq X (nth 1 Row))
(setq Y (nth 2 Row))
(setq Z (nth 3 Row))

 

You have to decide how you want to add attribute value to .csv file

Placement inside a row is not important as long as you know which element in row list will be assigned to particular variable. Elements inside list are counts starting from 0.

 

One option is

 

(setq Row (read (strcat "(" Row ")")))
(setq ATT1 (vl-symbol-name (nth 0 Row)))
(setq ATT2 (vl-symbol-name (nth 1 Row)))
(setq X (nth 2 Row))
(setq Y (nth 3 Row))
(setq Z (nth 4 Row))

 

 

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

cadffm
Consultant
Consultant

@Anonymous  schrieb:

Are you suggesting everything under Var1 should be the new code rather than just change for the comments in the original code?


I am not sure if my code works well, i just pointet to the important part of your question,

you posted an incomplete package what cannot be easily tested..

in this cases do not all what is possible for me, because it isn't my job 😉

Upload complete sample (code, DWG with your blocks ad one csv file), then it is easy to test and to help you with your problems,

otherwise we have unnecessary  work with it (and it isn't our problem).

 

 

Sebastian

0 Likes

Anonymous
Not applicable

Thanks for the response.

This adds clarity as the second attribute is the same as the first attribute for my applicaiton and I can make them the same row. As strange as that sounds I am adding 'halo' blocks on maps where the background attribute is white (as well as larger than the top attribute) and has the same value as the attribute above it in order for it to show better on a map image.

0 Likes

Anonymous
Not applicable

I tried that and it seems t be getting caught up in an "attreq" point.

I have attached the code for a BH-Halo insertion with the changes and additions as far as I know.

The block and .csv are also attached.

0 Likes

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I tried that and it seems t be getting caught up in an "attreq" point.

 


If you already setup the the correct values for both ATTDIA and ATTREQ, then you dont need this lines anymore.

 

    (setq b1 (entget (entnext (entlast))))
    (setq ff1 (assoc 1 b1))
    (setq xx1 (cons 1 ATT1))
    (entmod (subst xx1 ff1 b1))

 

as stated at post #4

 

(defun c:I-BH-Halo (/ fn fp lst l)
  (setq fn (getfiled "Select CSV file" "" "csv" 4))
  (setq	fp  (open fn "r")
	lst '()
  ) ;_ end of setq
  (while (setq l (read-line fp))
    (setq lst (cons l lst))
  ) ;_ end of while
  (close fp)
  (setq VAL (getvar "attreq"))
  (command "attreq" 1)
  (command "attdia" 0)
  (foreach Row lst
    (while (if (setq n (vl-string-search "," Row 0))
	     (setq Row (vl-string-subst " " "," Row))
	   ) ;_ end of if
    ) ;_ end of while
    (setq Row (read (strcat "(" Row ")")))
    (setq ATT1 (vl-symbol-name (nth 0 Row)))
    (setq ATT2 (vl-symbol-name (nth 0 Row)))
    (setq X (nth 1 Row))
    (setq Y (nth 2 Row))
    (setq Z (nth 3 Row))
    (setq PT1 (list X Y Z))
    (command "insert" "BH-Halo" PT1 "1" "" "" ATT1 ATT2)    
  ) ;_ end of foreach
  (command "attreq" VAL)
) ;_ end of defun

 

 

0 Likes

Anonymous
Not applicable

Thanks 'pbelse'.

I'm more than a little rusty with My LISP these days.

0 Likes