Add an attribute

Add an attribute

Anonymous
Not applicable
804 Views
2 Replies
Message 1 of 3

Add an attribute

Anonymous
Not applicable

Hello guys.
I use the following code to insert some blocks into autocad.
the code below inserts using this methodology >> ATT1; 433360,9367221 <<
and works perfectly.
But I would like to add a second attribute >> ATT1; ATT2; 433360,9367221 <<
Does anyone already have a code ready for this?

 

(defun c:Test (/ T_BlockName T_VarList T_CurValues T_DataFile T_DataFile T_DataLine T_DataFields)
   (setq T_BlockName "POSTE9_3")
   (setq T_VarList '("CMDECHO" "OSMODE" "ATTREQ" "ATTDIA"))
   (setq T_CurValues (mapcar 'getvar T_VarList))
   (mapcar 'setvar T_VarList '(0 0 1 0))
   (if
      (and
         (or
            (tblsearch "BLOCK" T_BlockName)
            (setq T_BlockName (findfile (strcat T_BlockName ".dwg")))
         )
         (setq T_DataFile (getfiled "Select data file" "" "txt" 128))
      )
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (setq T_DataFileID (open T_DataFile "r"))
         (while
            (setq T_DataLine (read-line T_DataFileID))
            (if
               (= (length (setq T_DataFields (String2List T_DataLine ";"))) 2)
               (vl-cmdf "_.INSERT" T_BlockName (nth 1 T_DataFields) "" "" "" (nth 0 T_DataFields))
            )
         )
         (close T_DataFileID)
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
      (alert " ** Block not found or no data file selected!")
   )
   (mapcar 'setvar T_VarList T_CurValues)
   (princ)
)
     
(defun String2List (S2L_String S2L_Delimiter / S2L_Return S2L_End S2L_EndPos S2L_Item)
  (setq S2L_End nil)
  (while
     (and
        (setq S2L_EndPos (vl-string-search S2L_Delimiter S2L_String))
        (not S2L_End)
     )
     (if
        S2L_EndPos
        (progn
	   (setq S2L_Item (substr S2L_String 1 S2L_EndPos))
           (if
              (/= S2L_Item "")
              (setq S2L_Return (append S2L_Return (list S2L_Item)))
           )           
	   (setq S2L_String (substr S2L_String (+ S2L_EndPos 2)))
        )
        (setq S2L_End T)
     )   
  )
  (if
     (/= S2L_String "")
     (setq S2L_Return (append S2L_Return (list S2L_String)))
  )
  S2L_Return 
)
0 Likes
Accepted solutions (1)
805 Views
2 Replies
Replies (2)
Message 2 of 3

pbejse
Mentor
Mentor
Accepted solution
(while
            (setq T_DataLine (read-line T_DataFileID))
	    (setq T_DataFields (String2List T_DataLine ";"))
            (cond
	       ((= (length T_DataFields) 2)
			(vl-cmdf "_.INSERT" T_BlockName (nth 1 T_DataFields) "" "" ""
				 	(nth 0 T_DataFields))
			)	
               ((= (length T_DataFields) 3)
               		(vl-cmdf "_.INSERT" T_BlockName (nth 2 T_DataFields) "" "" ""
			 		(nth 0 T_DataFields) (nth 1 T_DataFields))
			)
		)
            )

 if you are using the same block.

 

((= (length T_DataFields) 2)
               	(vl-cmdf "_.INSERT" T_BlockName (nth 1 T_DataFields) "" "" "" (nth 0 T_DataFields) "")

I would suggest adding one more data on your external file source

 

BLOCKWITH1ATTRIBUTE;ATT1; 433360,9367221
BLOCKWITH2ATTRIBUTES;ATT1; ATT2; 433360,9367221

 

Message 3 of 3

Anonymous
Not applicable

Thank you very much @pbejse
It worked perfectly, but I do not understand what you mean by that?

 

I would suggest adding one more data on your external file source

 

BLOCKWITH1ATTRIBUTE;ATT1; 433360,9367221
BLOCKWITH2ATTRIBUTES;ATT1; ATT2; 433360,9367221

 

0 Likes