Author Topic: blocks and attributes  (Read 1992 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
blocks and attributes
« 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 :-
Code: [Select]
(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

Fatty

  • Guest
Re: blocks and attributes
« Reply #1 on: December 22, 2007, 04:31:05 AM »
Just replace slashes with double backslashes here,

change this line:

Code: [Select]
"C:/GOH-LISP/DWG04-NEW/GRIDCROSS.DWG"
on this one:

Code: [Select]
"C:\\GOH-LISP\\DWG04-NEW\\GRIDCROSS.DWG"
and it should work

~'J'~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: blocks and attributes
« Reply #2 on: December 22, 2007, 08:57:39 AM »
When you use the command to insert a block with attributes you must address the following system variables.
Code: [Select]
;|
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)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: blocks and attributes
« Reply #3 on: December 23, 2007, 04:02:32 PM »
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.

csgoh

  • Newt
  • Posts: 176
Re: blocks and attributes
« Reply #4 on: December 26, 2007, 07:57:39 AM »
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.