TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: csgoh on December 22, 2007, 04:13:13 AM
-
I am not very familiar with blocks which has attributes and I guess i need some help in the area from the gurus here.
I created a dwg "gridcross.dwg" which has 2 attributes "N" and "S".
I trying to write a lisp program to insert this block but it gives me an error "Automation Error. Key not found"
My code is as follows :-
(defun AGD_Cal ()
(setq GB:acadobj (vlax-get-acad-object)
;; acad Object
GB:ActivedocumentObj (vla-get-Activedocument GB:acadobj)
;;
;; IAcadDocument Object
;;
;; the current dwg
;;
;; IAcadModelspace Collection
;;
GB:mSpace (vla-get-ModelSpace GB:ActivedocumentObj)
;; the modelspace collection
)
(if (not (tblsearch "block" "GRIDCROSS"))
(progn
(setq blkref (vlax-invoke-method GB:mSpace 'insertblock
(vlax-3d-point '(0.0 0.0 0.0))
"C:/GOH-LISP/DWG04-NEW/GRIDCROSS.DWG" 1.0 1.0 1.0 0.0))
(setq atts (vlax-invoke blkref 'getattributes))
(foreach att atts
(if (eq (vla-get-tagstring att) "S")
(vla-put-textstring att "S")
(vla-put-textstring att "N")
)
);foreach
)
);IF
);end
Also, how can I rewrite such that when i insert the gridcross blcok, it does not prompt me for the values?
thank you in advance
-
Just replace slashes with double backslashes here,
change this line:
"C:/GOH-LISP/DWG04-NEW/GRIDCROSS.DWG"
on this one:
"C:\\GOH-LISP\\DWG04-NEW\\GRIDCROSS.DWG"
and it should work
~'J'~
-
When you use the command to insert a block with attributes you must address the following system variables.
;|
ATTDIA
Controls whether the -INSERT command uses a dialog box for attribute value entry. See "INSERT Command Line."
0 Issues prompts on the command line
1 Uses a dialog box
ATTMODE
Controls display of attributes.
0 Off: Makes all attributes invisible
1 Normal: Retains current visibility of each attribute: visible attributes are
displayed; invisible attributes are not
2 On: Makes all attributes visible
ATTREQ
Determines whether the INSERT command uses default attribute settings during insertion of blocks.
0 Assumes the defaults for the values of all attributes
1 Turns on prompts or dialog box for attribute values, as specified by ATTDIA
TEXTEVAL
Controls the method of evaluation of text strings.
0 All responses to prompts for text strings and attribute values are taken literally
1 Text starting with an opening parenthesis [ ( ] or an exclamation mark (!) is
evaluated as an AutoLISP expression, as for nontextual input
|;
(setq sysattdia (getvar "ATTDIA"))
(setq sysattreq (getvar "ATTREQ"))
(setq systxteva (getvar "TEXTEVAL"))
(setvar "ATTDIA" 0)
(setvar "ATTREQ" 1)
(setvar "TEXTEVAL" 0)
<do your lisp>
(setvar "ATTDIA" sysattdia)
(setvar "ATTREQ" sysattreq)
(setvar "TEXTEVAL" systxteva)
-
Once you get the InsertBlock method working, which Fatty's suggestion should do, you shouldn't be prompted when adding the block in this method.
-
thanks guys.
just one more question, i thought that the forward slash (/) is equal to double backslash (\\) in lisp and how come it doesn't work in the first place.