script question

script question

bustr
Advocate Advocate
1,106 Views
3 Replies
Message 1 of 4

script question

bustr
Advocate
Advocate

My script is meant to insert a column of blocks and fill out the attributes. It only fills in the attributes on the first block then stops working. This is what shows up in the text window. The text of the script is further down. Can someone take a look and tell me what is going wrong? Using AutoCAD 2016.

Command: -INSERT Enter block name or [?] <CABSL-ID>: CABSL-ID
Units: Unitless Conversion: 0'-1"
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: 0,0
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 1 Enter Y scale factor <use X scale factor>: 1
Specify rotation angle <0>: 0

Enter attribute values
CABLE ID <?>: 2IB-101 TS2
CABLE TYPE <50 PR #20 W/IND. SHLD.>: 24PR #18 W/IND SHLD
DRAWING REF 1 <TO>: FROM 2IB-101 TS2
DRAWING REF 2: SEE DWG 832-D-7122
DRAWING REF 3: CONT FROM DWG
DRAWING REF 4: 832-D-7813

Command: -INSERT Enter block name or [?] <CABSL-ID>:
Units: Unitless Conversion: 0'-1"
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: CABSL-ID
Point or option keyword required.
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: *Cancel*



attreq 1
attdia 0
-INSERT CABSL-ID 0,0 1 1 0
2IB-101 TS2
24PR #18 W/IND SHLD
FROM 2IB-101 TS2
SEE DWG 832-D-7122
CONT FROM DWG
832-D-7813
-INSERT CABSL-ID 0,-0.375 1 1 0
2IB-102 TS
24PR #18 W/IND SHLD
FROM 2IB-102 TS
SEE DWG 832-D-7121
CONT FROM DWG
832-D-7813
-INSERT CABSL-ID 0,-0.75 1 1 0
2TB-101 TS1
36TR #16 W/IND SHLD
FROM 2TB-101 TS1
SEE DWG 832-D-7125
CONT FROM DWG
XXXX
-INSERT CABSL-ID 0,-1.125 1 1 0
2TB-101 TS1
36TR #16 W/IND SHLD
FROM 2TB-101 TS1
SEE DWG 832-D-7125
CONT FROM DWG
832-D-7815
-INSERT CABSL-ID 0,-1.5 1 1 0
2DB-101 TS1
24PR #20 W/IND SHLD
FROM 2DB-101 TS1
SEE DWG 832-D-7120
CONT FROM DWG
832-D-
-INSERT CABSL-ID 0,-1.875 1 1 0
2IB-102 TS1
24PR #16 W/IND SHLD
FROM 2IB-102 TS1
SEE DWG 832-D-7121
CONT FROM DWG
832-D-
-INSERT CABSL-ID 0,-2.25 1 1 0
2DB-101 TS1
24PR #16 W/IND SHLD
FROM 2DB-101 TS1
SEE DWG 832-D-7120
CONT FROM DWG
832-D-7821
-INSERT CABSL-ID 0,-2.625 1 1 0
2DB-102 TS1
24PR #16 W/IND SHLD
FROM 2DB-102 TS1
SEE DWG 832-D-7121
CONT FROM DWG
832-D-7821

0 Likes
Accepted solutions (1)
1,107 Views
3 Replies
Replies (3)
Message 2 of 4

bustr
Advocate
Advocate
Accepted solution

Figured it out. Substitute two spaces for the block name in the following insert commands.

attreq 1
attdia 0
-INSERT CABSL-ID 0,0 1 1 0
2IB-101 TS2
24PR #18 W/IND SHLD
FROM 2IB-101 TS2
SEE DWG 832-D-7122
CONT FROM DWG
832-D-7813
-INSERT 0,-0.375 1 1 0
2IB-102 TS
24PR #18 W/IND SHLD
FROM 2IB-102 TS
SEE DWG 832-D-7121
CONT FROM DWG
832-D-7813
-INSERT 0,-0.75 1 1 0
2TB-101 TS1
36TR #16 W/IND SHLD
FROM 2TB-101 TS1
SEE DWG 832-D-7125
CONT FROM DWG
XXXX
-INSERT 0,-1.125 1 1 0
2TB-101 TS1
36TR #16 W/IND SHLD
FROM 2TB-101 TS1
SEE DWG 832-D-7125
CONT FROM DWG
832-D-7815
-INSERT 0,-1.5 1 1 0
2DB-101 TS1
24PR #20 W/IND SHLD
FROM 2DB-101 TS1
SEE DWG 832-D-7120
CONT FROM DWG
832-D-
-INSERT 0,-1.875 1 1 0
2IB-102 TS1
24PR #16 W/IND SHLD
FROM 2IB-102 TS1
SEE DWG 832-D-7121
CONT FROM DWG
832-D-
-INSERT 0,-2.25 1 1 0
2DB-101 TS1
24PR #16 W/IND SHLD
FROM 2DB-101 TS1
SEE DWG 832-D-7120
CONT FROM DWG
832-D-7821
-INSERT 0,-2.625 1 1 0
2DB-102 TS1
24PR #16 W/IND SHLD
FROM 2DB-102 TS1
SEE DWG 832-D-7121
CONT FROM DWG
832-D-7821

0 Likes
Message 3 of 4

pbejse
Mentor
Mentor

@bustr wrote:

My script is meant to insert a column of blocks and fill out the attributes. It only fills in the attributes on the first block then stops working. This is what shows up in the text window. The text of the script is further down. Can someone take a look and tell me what is going wrong? Using AutoCAD 2016.
..


Are you wanting to run this script on an opened drawing? or across multiple drawing files?  How a block is created is usually where the problem is when invoking the native command on a script.

 

I would suggest to use a short lisp like this:

 

(defun _insertblockandwriteattributes (blockname insertionpoint valuelist)
  (if (and
        (tblsearch "Block" blockname)    
  	   (Setq InsertedBlock (vlax-invoke (vlax-get (vla-get-ActiveLayout
                                               (vla-get-activedocument
                                                     (vlax-get-acad-object)))
                                         'Block) 'InsertBlock  insertionpoint  blockname
                                   1 1 1 0)
           )
        (minusp (vlax-get InsertedBlock 'HasAttributes)))
        
        (mapcar 'vla-put-textstring (vlax-invoke InsertedBlock 'Getattributes)
                valuelist)
    	   (princ "\nInvalid block"))
  (princ)
  )

 

and a script would look like this

 

(_insertblockandwriteattributes
"CABSL-ID" '(0.0 0.0 0.0)
'("2IB-101 TS2" "24PR #18 W/IND SHLD" "FROM 2IB-101 TS2" "SEE DWG 832-D-7122" "CONT FROM DWG" "832-D-7813"))
(_insertblockandwriteattributes
"CABSL-ID" '(0.0 -0.375 0.0)
'("2IB-102 TS" "24PR #18 W/IND SHLD" "FROM 2IB-102 TS" "SEE DWG 832-D-7121" "CONT FROM DWG" "832-D-7813"))

HTH

Message 4 of 4

bustr
Advocate
Advocate

Thanks. I figured out that I only needed to specify the bock name in the first insert command. When I removed it from the rest of the lines and substituted a space the script ran with no problems. Something has changed in AutoCAD because the original script used to work.

0 Likes