Define and insert blocks with attributes , using DXF codes and AutoLisp

Define and insert blocks with attributes , using DXF codes and AutoLisp

Anonymous
Not applicable
8,577 Views
60 Replies
Message 1 of 61

Define and insert blocks with attributes , using DXF codes and AutoLisp

Anonymous
Not applicable

Hello everyone !

 

I am trying to define a block with attributes with LockPosition = On , using DXF codes (280 . 1)  and AutoLisp (lisp c: TestPP attached below ) . For Visual Lisp , property LockPosition = Read Only , so can't be changed !

 

The problem is , this (280 . 1)  is having effect only if I introducing codes 100 in blue . But then , I have a problem with TextStyle (7 . "ArialT")  .

 

(defun c:TestPP ()
 (prinC "\n  TestPP  :  V  :  1 . 04 . 2019  ;")
 (setVar "TextStyle" "Standard")
 (vl-CmdF "_.Purge" "_A" "" "_N")

 (if (tblSearch "Block" "PxT")
  (princ "\n  Block  Existed !")
  (progn ; Define Block
   (command "_.Layer" "_N" "Name L" "_C" 1 "Name L" "")

;;;   (if (tblSearch "Style" "ArialT") T (vl-CmdF "_.Style" "ArialT" "Arial.ttf" 0 1 0 "_N" "_N") ) ;
;;;   (if (not (tblobjname "Style" "ArialT")) (vl-CmdF "_.Style" "ArialT" "Arial.ttf" 0 1 0 "_N" "_N") ) ;
;;;   (if (not (tblobjname "Style" "ArialT")) (vl-CmdF "-Style" "ArialT" "Arial.ttf" 0 1 0 "_N" "_N") ) ;
   (if (not (tblSearch "Style" "ArialT")) (vl-CmdF "-Style" "ArialT" "Arial.ttf" 0 1 0 "_N" "_N") ) ;


;;;   (cond ( (null (tblSearch "STYLE" "ELEV_ARIAL_1"))
;;;          (setq nw_style (vla-Add (vla-get-textStyles (vla-get-ActiveDocument (vlax-get-acad-Object))) "ArialT")
;;;                nw_font (strcat (getEnv "systemroot") "\\Fonts\\Arial.ttf")
;;;          ) ;end_setq
;;;          (mapcar '(lambda (pr val) (vlax-put-Property nw_style pr val))
;;;            (list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
;;;            (list nw_font 0.0 (/ (* 0.0 pi) 180) 1.0 0.0)
;;;          ) ;end_mapcar
;;;        )
;;;   ) ;end_cond
  
   (entMake '((0 . "BLOCK") (2 . "PxT") (70 . 2) (8 . "0") (10 0 0 0) (6 . "ByLayer") (62 . 256) (4 . "Made by Me"))  ) ; end of e
   (entMake (list '(0 . "Circle") '(8 . "0") '(62 . 256) '(6 . "ByLayer") '(10 0 0 0) (cons 40 0.25) ) ) ; end of e

   (entMake (list '(0 . "AttDef") '(100 . "AcDbEntity") (cons 8 "Name L") '(62 . 256) '(6 . "ByLayer") ;'(67 . 0)
                  '(100 . "AcDbText") '(10 0 0 0) '(40 . 1.5) '(1 . "N") '(50 . 0) '(41 . 1) '(51 . 0) '(7 . "ArialT") '(71 . 0) '(72 . 0)
                            '(11 0.5 +1.0 0) '(210 0.0 0.0 1.0)
                  '(100 . "AcDbAttributeDefinition") '(280 . 0) '(3 . "Point Name") '(2 . "NAME") '(70 . 0) '(73 . 0) '(74 . 2) '(280 . 1) ) ) ; end of e  ;'(100 . "AcDbXrecord") 

   (entMake '((0 . "EndBlk") (8 . "0")) ) ; end of e
   (prinC "\n   Block  with  Attributes  DEFINED  :  PxT  ;") ; end of p
  ) ; else
 ) ; if

 (setq ;q (getString "\n   Attribute  Insertion  with  Codes  100  :  Any = NO  ;   <  Enter = YES  >  :  ")
       i 0)

 (repeat 10 ; Inserting 10 Blocks with Attribute
  (entMake (list '(0 . "Insert") '(2 . "PxT") '(8 . "0") '(66 . 1) (cons 10 (trans (list i i i) 1 0)) '(50 . 0) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0)) ) ; inserare Bloc

  (if (= (rem i 2) 0) ;(= q "")
  (entMake (list '(0 . "ATTRIB") '(100 . "AcDbEntity") '(8 . "Name L") '(67 . 0) ;'(6 . "ByLayer") ;'(62 . 256) '(67 . 0) ;0 = MSpace ;
                 '(100 . "AcDbText") (list 10 i i i) '(40 . 1) (cons 1 (ItoA i)) '(50 . 0) '(41 . 1.0) '(51 . 0.0)  '(7 . "ArialT")
                        '(71 . 0) '(72 . 0) (cons 11 (trans (list i i i) 1 0)) ;'(210 0.0 0.0 1.0)
                 '(100 . "AcDbAttribute") '(280 . 0) '(2 . "NAME") '(70 . 0) '(73 . 0) (cons 74 2) '(280 . 1) )  ) ; set Attribute


  (entMake (list '(0 . "ATTRIB") (list 10 i i i)  '(8 . "Name L") (cons 1 (ItoA i)) '(280 . 0) '(2 . "NAME") '(40 . 1) '(70 . 0)
             (cons 11 (trans (list i i i) 1 0)) (cons 72 0) (cons 74 2) '(6 . "ByLayer") '(7 . "ArialT") '(50 . 0) '(62 . 5) '(280 . 1) )  ) ; e
  ) ; if
  (entMake '((0 . "SeqEnd") (8 . "0")) ) ; End Insert Block !

  (setq i (1+ i))  
 ) ; r

 (setVar "TextStyle" "Standard") (command "zoom" "e")
 (prinC (strCat "\n   Inserted  :  " (ItoA i) "  ;"))
 (prinC "\n   TestPP  :  END  ;") (prinC)
) ; defun c:TestPP

I create a condition which is alternating the insertion of the attributes .

Open a new dwg , load and run the lisp . The only difference will be too many grips for blue and odd numbers , because (280 . 1) is not having any effect .

Delete all and run the lisp again . Only the blue and odd attributes are visible . 

 

For a manual insertion , TextStyle for attribute is Standard . 

So , at the same time , the same block can have different appearances / properties as : color , height , layer rotation , etc .

 

If I keep the TextStyle ArialT preserved in the drawing , as current Text Style or used somewhere else , are NO problems . 

 

Any idea ? 

 

Thanks in advance .

 

 

0 Likes
Accepted solutions (1)
8,578 Views
60 Replies
Replies (60)
Message 61 of 61

Anonymous
Not applicable

Thank you very much for your contribution dlanorh .

 

your suggested link is similar to my work . They are trying to define a block with few attributes , with different position around to the insertion point . I have done all of this (see the attached picture , Points 1.jpg ) .

 

I am using this lisp from 6 years .

I can set TextStyle with '(7 . "ArialT") and LuckPosition = On for the definition of  AttDef , with :

 

(setq attO (vla-Item blockP e))

(vla-Put-LockPosition attO acLock)

But, for insertion with entMake for "Attrib" , the default properties from the definition ( as TextStyle and LuckPosition ), are NOT coming active as in the definition ! Are coming active from AutoCAD default values .

So , for TextStyle is coming "Standard" and for LuckPosition = Off (280 . 0) .

 

Please read my MESSAGE 47 .

 

As in your link ,

« Reply #3 on: September 06, 2013, 01:40:59 PM »
. . . . .
Other than simple single ATTRIBUTES, I believe that for ATTRIbuted BLOCKs that
the (command "_.INSERT" ....) is much easier.
Translating the text points can be quite a daunting task.

-David

So ,  (command "_.INSERT" ....)  is working fine , the Attributes will have ALL the properties from definition , including  LuckPosition = ON , BUT it is slower than entMake .

 

So , I am inserting attributes as below , with no problem , except (280 . 1)  which is not taking any effect ! 

(entMake (list '(0 . "ATTRIB") (list 10 i i i)  '(8 . "Name L") (cons 1 (ItoA i)) '(280 . 0)
'(2 . "NAME") '(40 . 1) '(70 . 0) (cons 11 (trans (list i i i) 1 0)) (cons 72 0) (cons 74 2)
'(6 . "ByLayer") '(7 . "ArialT") '(50 . 0) '(62 . 5) '(280 . 1) ) )

 

Now , 2 weeks ago , I had the idea to introduce in entMake list , the dxf codes 100 's . And surprise , (280 . 1) is having an effect .  But another problem occured : the Attributes are not displayed because the custom TextStyle "ArialT" was not associated . Even the "Standard" one .

 

This is why the topic is : define / insert a Block with Attributes using : entMake + (7 . "ArialT") + (280 . 1) .

 

Regards ,

 

Costin

 

0 Likes