Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding Second Atribute to Inserted Block

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Anonymous
1222 Views, 12 Replies

Adding Second Atribute to Inserted Block

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)?

Labels (2)
12 REPLIES 12
Message 2 of 13
pbejse
in reply to: Anonymous


@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)
)

 

Message 3 of 13
cadffm
in reply to: Anonymous

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

EESignature

Message 4 of 13
pbejse
in reply to: cadffm


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

 

Message 5 of 13
cadffm
in reply to: cadffm

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

EESignature

Message 6 of 13
Anonymous
in reply to: cadffm

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.

 

Message 7 of 13
Anonymous
in reply to: cadffm

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

Message 8 of 13
hak_vz
in reply to: Anonymous

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.
Message 9 of 13
cadffm
in reply to: Anonymous


@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

EESignature

Message 10 of 13
Anonymous
in reply to: hak_vz

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.

Message 11 of 13
Anonymous
in reply to: hak_vz

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.

Message 12 of 13
pbejse
in reply to: Anonymous


@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

 

 

Message 13 of 13
Anonymous
in reply to: pbejse

Thanks 'pbelse'.

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta