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,809 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,810 Views
60 Replies
Replies (60)
Message 41 of 61

Anonymous
Not applicable

I find something very interesting :

 

1 . open a new dwg , load TestPP and run it ;

2. delete ALL and run again ; red attributes are missing ;

3. delete ALL , PURGE and SAVE the dwg and CLOSE it .

 

4. Open the saved file , load and run TestPP , interesting , it is working with no problem .

 

Something from TextStyle ArialT is staying in dwg after PURGE command in the second run , which is causing troubles . Something residual which is disappearing after SAVE command and OPEN .

 

Costin

 

0 Likes
Message 42 of 61

Moshe-A
Mentor
Mentor

Good Morning,

 

even if this works (and now i'm not on my computer so i can not check) you agree that someting is wrong here. i can not believe they meant it will come up this way so it's maybe some bug... and the question is why they did not fix it along the road?

beyond that if does not work with (entmake) atleast you expect it will go with activex - no?!

 

moshe

 

0 Likes
Message 43 of 61

Anonymous
Not applicable

Good morning to you too !

 

At the moment , I find 3 options :

 

Option 1 : preserve the TextStyle ArialT before to PURGE the drawing .

 

(defun c:TestPP1 ()
 (prinC "\n  TestPP1  :  V  :  1 . 04 . 2019  ;")

 (if (null (tblSearch "Style" "ArialT"))
    (vl-cmdf "Style" "ArialT" "arial" 0 1 0 "_N" "_N")
    (progn (princ "\n  ArialT  Existed !") (setvar "TextStyle" "ArialT") )
 ) ; if
 
 (vl-CmdF "_.Purge" "_A" "" "_N")

 (if (tblSearch "Block" "PxT")
  (princ "\n  Block  Existed !")
  (progn ; else Define Block
   (command "_.Layer" "_N" "Name L" "_C" 1 "Name L" "")
  
   (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) '(10 0 0 0)
                  '(100 . "AcDbText") '(10 0.5 +1.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 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)
  (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 0) '(40 . 1) (cons 1 (ItoA i)) '(50 . 0) '(41 . 1.0) '(51 . 0.0)  '(7 . "ArialT")
                        '(71 . 0) '(72 . 0) (cons 11 (list i i i)) ;'(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

 (command "zoom" "e")
 (prinC (strCat "\n   Inserted  :  " (ItoA i) "  ;"))
 (prinC "\n   TestPP1  :  END  ;") (prinC)
) ; defun c:TestPP1

 

Option 2 : use Visual Lisp to set TextStyle from Standard to ArialT , for definition AND insertion of Attributes ;

 

(defun c:TestPP2 ()
 (prinC "\n  TestPP2  :  V  :  20 . 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 (or (null (tblSearch "Style" "ArialT")) (not (tblObjName "Style" "ArialT")) )
  (vl-cmdf "Style" "ArialT" "arial" 0 1 0 "_N" "_N")
  (princ "\n  Text  Style  :  ArialT  :  Existed  !") ;(setvar "TextStyle" "ArialT")
 )
   
   (entMake '((0 . "BLOCK") (2 . "PxT") (8 . "0") (70 . 2) (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.5 +1.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

   (setq AcdObj (vlax-Get-Acad-Object)  ActDoc (vla-Get-ActiveDocument AcdObj)  MSpace (vla-Get-ModelSpace ActDoc)  Blocks (vla-Get-Blocks ActDoc) )
   (if (and (tblSearch "Block" "PxT") (setq lisOB nil  blockP (vla-Item Blocks "PxT") )  ) ; end of s (vlax-Dump-Object blockP T)
      (progn
;;;     (forEach e '(4 5 6 7) (if (vlax-Property-Available-P (setq attO (vla-Item blockP e)) "LockPosition") (vla-Put-LockPosition attO acLock) (alert "NO  LockPosition  for  Attributes  !") ) ) ; end of f
       (setq attO (vla-Item blockP 1)) (vla-Put-StyleName attO "ArialT")
       (vla-Put-BlockScaling blockP acUniform) ; -1 = Scalare Uniforma la Inserare in alt Desen ! :vlax-False = 0 ; :vlax-True = 1 ; 281
       (vla-Put-Explodable blockP 0) ; end of vla
       (vla-Put-Units blockP 6) ; end of vla ; 0 = UniLess ; 1 = inch ; 4 = mm ; 6 = m ;
    )) ; if
   
   (prinC "\n   Block  with  Attributes  DEFINED  :  PxT  ;") ; end of p
  ) ; else
 ) ; if

 (setq 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)) ) ; Insert Block

  (if (= (rem i 2) 0)
  (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 0) '(40 . 1) (cons 1 (ItoA i)) '(50 . 0) '(41 . 1.0) '(51 . 0.0) ; '(7 . "ArialT")
                        '(71 . 0) '(72 . 0) (cons 11 (list i i i)) ;'(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 !

  (if (setq lAtrN (vlax-invoke (vlax-Ename->Vla-Object (entLast)) "GetAttributes") )
   (forEach e lAtrN (vla-Put-StyleName e "ArialT") )
  ) ; if
  
  (setq i (1+ i))  
 ) ; r

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

 

Option 3 : use Visual Lisp to set the LockPosition = ON , but only for definition of Attributes and use Visual Lisp to set TextStyle from Standard to ArialT only for inserted blocks with Attributes .

 

(defun c:TestPP3 ()
 (prinC "\n  TestPP3  :  V  :  20 . 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 (or (null (tblSearch "Style" "ArialT")) (not (tblObjName "Style" "ArialT")) )
  (vl-cmdf "Style" "ArialT" "arial" 0 1 0 "_N" "_N")
  (princ "\n  Text  Style  :  ArialT  :  Existed  !") ;(setvar "TextStyle" "ArialT")
 )
   
   (entMake '((0 . "BLOCK") (2 . "PxT") (8 . "0") (70 . 2) (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") (cons 8 "Name L") '(62 . 256) '(6 . "ByLayer") ;'(67 . 0)
                  '(10 0.5 +1.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)
                  '(280 . 0) '(3 . "Point Name") '(2 . "NAME") '(70 . 0) '(73 . 0) '(74 . 2) '(280 . 1) ; is NOT working !
   ) ) ; end of e

   (entMake '((0 . "EndBlk") (8 . "0")) ) ; end of e

   (setq AcdObj (vlax-Get-Acad-Object)  ActDoc (vla-Get-ActiveDocument AcdObj)  MSpace (vla-Get-ModelSpace ActDoc)  Blocks (vla-Get-Blocks ActDoc) )
   (if (and (tblSearch "Block" "PxT") (setq blockP (vla-Item Blocks "PxT") )  ) ; end of s (vlax-Dump-Object blockP T)
     (progn
       (if (vlax-Property-Available-P (setq attO (vla-Item blockP 1)) "LockPosition") (vla-Put-LockPosition attO acLock) (alert "NO  LockPosition  for  Attributes  !") )
       (vla-Put-BlockScaling blockP acUniform) ; -1 = Scalare Uniforma la Inserare in alt Desen ! :vlax-False = 0 ; :vlax-True = 1 ; 281
       (vla-Put-Explodable blockP 0) ; end of vla
       (vla-Put-Units blockP 6) ; end of vla ; 0 = UniLess ; 1 = inch ; 4 = mm ; 6 = m ;
    )) ; if
   
   (prinC "\n   Block  with  Attributes  DEFINED  :  PxT  ;") ; end of p
  ) ; else
 ) ; if

 (setq 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)) ) ; Insert Block

  (if (= (rem i 2) 0)
  (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 0) '(40 . 1) (cons 1 (ItoA i)) '(50 . 0) '(41 . 1.0) '(51 . 0.0) ; '(7 . "ArialT") ; is NOT working !
                        '(71 . 0) '(72 . 0) (cons 11 (list i i i)) ;'(210 0.0 0.0 1.0)
                 '(100 . "AcDbAttribute") '(280 . 0) '(2 . "NAME") '(70 . 0) '(73 . 0) (cons 74 2) '(280 . 1) ; it is working !
   ) ) ; 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 !

  (if (setq lAtrN (vlax-invoke (vlax-Ename->Vla-Object (entLast)) "GetAttributes") )
   (forEach e lAtrN (vla-Put-StyleName e "ArialT") )
  ) ; if
  
  (setq i (1+ i))  
 ) ; r

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

 

I am still expecting to find the problem for Option 1 , because is the faster one . I need to use this application to read a text file and insert thousands of blocks with 4 Attributes each .

 

 

 

Regards ,

 

Costin

0 Likes
Message 44 of 61

Moshe-A
Mentor
Mentor

i give up (as opposed to you i'm allowed Smiley LOL) but i still think locking the layer is good solution under the circumstances and YES if it's locked you can not edit the attributes, that's why i said you should handle this on your own [like adding a command to give users special access (temporary unlock it) to edit those attributes value and right after lock it back]

 

moshe

 

0 Likes
Message 45 of 61

Anonymous
Not applicable

I still hope , somebody from AutoDesk , with more experience in AutoLISP and DXF can guide us on this topic .

 

Very easy : define / insert a Block with Attributes using : entMake + (7 . "ArialT") + (280 . 1) .

(a specified TextStyle and LuckPosition = ON ) .

 

Just a simple task , nothig more .

 

Until next time , 

 

Good coding time ! 

0 Likes
Message 46 of 61

dlanorh
Advisor
Advisor

Why are you trying to reset the lockposition property? If it is set when defining the block it will always be locked.

 

If you define a block with an attribute, and set the attributes LockPosition to True; when you insert a block reference of that block the attributes position is locked.  Test it yourself by inserting that block then

 

(vlax-dump-object (vlax-ename->vla-object (car (nentsel))))

 

selecting the attribute.

 

The LockPosition property (an activex property) shows as :  LockPosition (RO) -1.

 

This is ON as :vlax-true = -1 and :vlax-false = 0

 

To quote "Tony Tanzillo" from here https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vlax-true-vlax-false/td-p/863190

 

ActiveX uses a different means of representing
boolean logic (true/false) than LISP does.

In LISP, nil is the only value that is interpreted
logically as "false", and *everything* else is
interpreted as "true".

In ActiveX, :vlax-true and :vlax-false (which are
-1 and 0 respectively), are used to represent true
and false.

 

I am not one of the robots you're looking for

0 Likes
Message 47 of 61

Anonymous
Not applicable

Hello  dlanorh ,

 

That is very weird ,

 

In the definition of the block with attributes , the Attributes have the TextStyle = ArialT , (7 . "ArialT")

and LuckPosition = ON (280 . 1) ;

 

But , if you don't set again in the insertion process : (7 . "ArialT") and (280 . 1) , the inserted attributes with lisp , will not be as in the definition , unfortunately , will be as default : (7 . "Standard") and (280 . 0) .

 

If you will try to insert this bloc with command : _insert , will be no problem , as in the definition .

 

Interesting .

 

Run yourself the code below . Run , delete all and run again .

(defun c:TestPP0 ()
 (prinC "\n  TestPP0  :  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") ) ;

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

;;; (setVar "TextStyle" "ArialT")
 (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   TestPP0  :  END  ;") (prinC)
) ; defun c:TestPP0

 

In the definition of Attributes , always LuckPosition = ON , but just in the definition . 

 

I have tried and , unfortunately for blue attributes , the result is :

;   LockPosition (RO) = 0

 the red's one are invisible.

 

Try to remove from insertion part (7 . "ArialT") and (280 . 1) and check what values are after insertion ?

Unfortunately as this : (7 . "Standard") and (280 . 0) .

 

As I said , what is the point to set something as default in the definition if is not applying . They will have other default as AutoCAD settings .

 

Regards ,

 

Costin

0 Likes
Message 48 of 61

Moshe-A
Mentor
Mentor

not really gave up Smiley LOL

 

did you know? if you use activex to insert the block (vla-insertblock) it will fully comply with the block definition and set lock position to ON and  YES i know ActiveX is less faster but still faster than (command "insert") you got to solved this somehow, NO?!

 

Moshe

 

 

(defun c:TestPP (/ attdef_lock_position ; local function
		   bname)

 (defun attdef_lock_position (/ AcDbBlockTableRecord)
  (setq AcDbBlockTableRecord (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bname))
  
  (vlax-for AcDbEntity AcDbBlockTableRecord
   (if (eq (vla-get-objectName AcDbEntity) "AcDbAttributeDefinition")
    (vlax-put AcDbEntity 'lockPosition :vlax-true)
   )
   (vlax-release-object AcDbEntity) 
  )

  (vlax-release-object AcDbBlockTableRecord)  
 ); attdef_lock_position

  
 (prinC "\n  TestPP  :  V  :  1 . 04 . 2019  ;")
  
 (setVar "TextStyle" "Standard")
 (vl-CmdF "_.Purge" "_A" "" "_N")
  
 (if (null (tblSearch "Style" "ArialT"))
  (vl-cmdf "Style" "ArialT" "arial" 0 1 0 "_N" "_N")
  (setvar "TextStyle" "ArialT")
 )


 (if (tblSearch "Block" "PxT")
  (princ "\n  Block  Existed !")
  (progn ; Define Block
   (command "_.Layer" "_N" "Name L" "_C" 1 "Name L" "")
   (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.0 0.0) '(40 . 0.25) ) ) ; end of e

   (entMake (list '(0 . "ATTDEF") '(8 . "Name L") '(62 . 256) '(6 . "ByLayer") ;'(67 . 0)
                  '(10 0.0 0.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.0) '(210 0.0 0.0 1.0) '(3 . "Point Name") '(2 . "NAME") '(70 . 0) '(73 . 0) '(74 . 2))) ; end of e  ;'(100 . "AcDbXrecord") 

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


 (setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
 (setq ;q (getString "\n   Attribute  Insertion  with  Codes  100  :  Any = NO  ;   <  Enter = YES  >  :  ")
       i 0)
  
 (repeat 10 ; Inserting 10 Blocks with Attribute
  (setq blkref (vla-insertblock ms (vlax-3d-point (trans (list i i 0.0) 1 0)) "PxT" 1.0 1.0 1.0 0.0))
   
  (if (= (rem i 2) 0) ;(= q "")
   (foreach attrib (vlax-invoke blkref 'GetAttributes)
    (vla-put-textString attrib (itoa i))
   )
   ; else
   (foreach attrib (vlax-invoke blkref 'GetAttributes)
    (vla-put-textString attrib (itoa i))
    (setq color (vla-get-trueColor attrib))
    (vla-put-colorIndex color acBlue)
    (vla-put-trueColor attrib color) 
   )
    
  ) ; if

  (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

0 Likes
Message 49 of 61

Anonymous
Not applicable

You have right Moshe ,

 

 ActiveX is nice for Get / Put a Layer , color , Text ... 

but is not so friendly working with coordinates  (x , y , z) .

You need to convert the point list p=(list x y z) => (vlax-3D-Point p) , and so on . variants ....Smiley Sad

Unfortunately , I am not a programmer , just an ordinary guy with DXF problems .

 

And the DXF is the base of AutoCAD . Should work .

Dont' you think ? If don't , fix it , to work .

 

As I said , the topic is : define / insert a Block with Attributes using : entMake + (7 . "ArialT") + (280 . 1) .

 

It is a very simple task , which should work from the beginning , without any problem !

 

Somewhere it is something deeply buried in this entMake function . 

Let's discovered !

0 Likes
Message 50 of 61

Moshe-A
Mentor
Mentor

@Anonymous wrote:

 

 ActiveX is nice for Get / Put a Layer , color , Text ... 

but is not so friendly working with coordinates  (x , y , z) .

You need to convert the point list p=(list x y z) => (vlax-3D-Point p) , and so on . variants ....Smiley Sad

so what?

 

And the DXF is the base of AutoCAD . Should work .

Dont' you think ? If don't , fix it , to work .

You think you can fix an AutoCAD bug?!

 

As I said , the topic is : define / insert a Block with Attributes using : entMake + (7 . "ArialT") + (280 . 1) .

 

It is a very simple task , which should work from the beginning , without any problem !

 

Somewhere it is something deeply buried in this entMake function . 

or not?!

 

 


do i sense that you don't really interested in solving the problem?!

 

 

Good Luck  Smiley LOL

moshe

 

 

0 Likes
Message 51 of 61

Anonymous
Not applicable

I am interested to find a solution for entMake and DXF .

 

I knew : ActivX , VBA , .NET , C++ , C# .... are alternative ways to do it .

I already admit some Visual Lisp options in Message 43 , as temporary solutions .

 

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

 

If someone else has any ideas / opinions about this , I am glad to hear it .

 

Regards ,

 

Costin

0 Likes
Message 52 of 61

dlanorh
Advisor
Advisor

Then perhaps the answer is NOT possible.

 

Extract from entmake : full page HERE

 

For legacy reasons, entmake ignores DXF group code 100 data for the following entity types:

    AcDbText
    AcDbAttribute
    AcDbAttributeDefinition 
    AcDbBlockBegin
    AcDbBlockEnd
    AcDbSequenceEnd
    AcDbBlockReference 

You need to include 100 codes to use 280 codes but entmake itself ignores them.

I am not one of the robots you're looking for

Message 53 of 61

Moshe-A
Mentor
Mentor

@Anonymous ,

 

good morning,

 

why are you keep rasing the ArialT text style? if you were changing it? it will start work - no?!

according to your last picture this is another reason why (entmake) is problematic.

by the way have you tried (entmakex)?

 

you know if you insist on (entmake) define your own fuction (CostinEntMake) and the implementation would be activex and no one has to know, i'll promise to keep my mouth shut Smiley LOL

 

have a nice day

moshe

 

0 Likes
Message 54 of 61

Anonymous
Not applicable

Thank you very much dlanorh ,

Good observation !

 

Now , we have the ensure . Can't be done in totality with entMake

 

Truly disappointed , but , this is the life , sometimes I need to accept the defeat  .

 

Any way , I still have 2 wonders :

1 . why / how it is working on the first time ?

2 . if 100 dxf codes are ignored by AutoCAD , why (280 . 1) it is having effect only together with ALL (100 . "AcDb....")

 

Regards ,

 

Costin

 

 

0 Likes
Message 55 of 61

dlanorh
Advisor
Advisor

@Anonymous wrote:

Any way , I still have 2 wonders :

1 . why / how it is working on the first time ?

2 . if 100 dxf codes are ignored by AutoCAD , why (280 . 1) it is having effect only together with ALL (100 . "AcDb....")


1. The lisp is probably inadvertently altering or breaking something; but I cannot see what it is.

DXF code 280 IIRC  has three meanings see HERE

Perhaps using it "out of context" when entmake ignores the 100 codes exposes  a coding bug

 

2. Autolisp like Visual Lisp cannot do everything. Consider an anonymous  blocks 'effectivename property. This is also a (RO) property and cannot be accessed via (entget) only being visible via "activex"

 

If we eliminate all command calls apart from the initial (purge) and use activex to set the 'lockposition property of the block definition and then insert instances of the block; it seems to work. See attached mash up code

 

Increase the repeat integer to get some idea of how long it takes (you may have to wait 5-10 seconds for 5000 iterations).

 

I am not one of the robots you're looking for

0 Likes
Message 56 of 61

Anonymous
Not applicable

Thank you very much  dlanorh ,

 

I will consider then ActiveX / Visual Lisp as a solution for this entMake AutoLisp function for "Insert" and "ATTRIB" .

 

Just a remark ,

if I cancel ONLY ;(7 . "ArialT") from the definition & insertion of Attributes and keeping all 100's , everything is working fine .

 

Interesting any way !

 

Regards ,

 

Costin

0 Likes
Message 57 of 61

dlanorh
Advisor
Advisor

@Anonymous wrote:

 

Just a remark ,

if I cancel ONLY ;(7 . "ArialT") from the definition & insertion of Attributes and keeping all 100's , everything is working fine .


 

When I tried that with the insertion, it defaulted to "Standard" on my system (romans font). Is "Standard" on your system be  ("arial" font)?

I am not one of the robots you're looking for

0 Likes
Message 58 of 61

Anonymous
Not applicable

Yes ,

 

picture attached .

 

so , this should be the conflict ?

 

But , why it is running fine for the first time ? Standard = Arial too . 

And why it is a problem in entMake with 100's dxf and no problem all the time without 100's dxf ?

 

it looks like we're coming closer .

 

Regards ,

 

Costin

0 Likes
Message 59 of 61

Anonymous
Not applicable

Unfortunately , is not .

 

I changed Standard = Calibri .

 

in the second run , I have the same problem with red Attributes .  

 

Oh ,

 

Was to easy to be true !

0 Likes
Message 60 of 61

dlanorh
Advisor
Advisor

This is how  I think the repeat should be structured.I've opened up the entmake lists to enable easier commenting out.

 

Having two entmakes for a simple color change wastes code. You only need to do it once and set the color (variable clr) in the if statement. It then requires a (cons 62 clr). The attribute insertion point (code 11) was also incorrect. The insertion point as in the definition should be (+0.5 +1.0 0.0) from the block insertion point. This may have been causing problems.

 

  (setq clr nil
        i_pt nil
  )
 (repeat 10 ; Inserting 10 Blocks with Attribute
    (entmake  (list '(0 . "Insert") 
                    '(2 . "PxT") 
                    '(8 . "0") 
                    (cons 10 (trans (list i i i) 1 0)) 
                    '(50 . 0) 
                    '(41 . 1.0) 
                    '(42 . 1.0) 
                    '(43 . 1.0)
                    '(66 . 1) 
              ) 
    );end_entmake Block

  (if (= (rem i 2) 0) (setq clr 256) (setq clr 5));sets the attribute color
   
  ; This sets the correct insertion point for the attribute relative to the block
(setq i_pt (mapcar '(lambda (x y) (+ x y)) (trans (list i i i) 1 0) (list 0.5 1.0 0.0))) ;I have commented out the 100 codes as entmake is supposed to ignore them, and also the 280 codes as these won't work without the 100 codes (entmake (list '(0 . "ATTRIB") ;'(100 . "AcDbEntity") '(8 . "Name L") '(67 . 0) (cons 62 clr) ;'(100 . "AcDbText") (list 10 0.0 0.0 0.0);IIRC this is needed but ignored '(40 . 1) (cons 1 (itoa i)) '(50 . 0) '(41 . 1.0) '(51 . 0.0) '(7 . "ArialT") '(71 . 0) '(72 . 0) (cons 11 i_pt) ;'(100 . "AcDbAttribute") ;'(280 . 0) '(2 . "NAME") '(70 . 0) '(73 . 0) (cons 74 2) ;'(280 . 1) ) );end_entmake Attribute (entmake '((0 . "SeqEnd") (8 . "0"))) (setq i (1+ i)) );end_repeat

I also think this would make interesting reading  https://www.theswamp.org/index.php?topic=45268.0

I am not one of the robots you're looking for

0 Likes