Author Topic: Inserting Block, but reading from Excel  (Read 10572 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Inserting Block, but reading from Excel
« Reply #15 on: January 18, 2010, 01:33:23 PM »
You might try this. {Untested}

Code: [Select]
(defun c:blkins (/ AllData data *error*)
;|
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
|;
 
  ;; error function & Routine Exit
  (defun *error* (msg)
    (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    )               ; endif
    (and sysattdia (setvar "ATTDIA" sysattdia)) ; reset vars
    (and sysattreq (setvar "ATTREQ" sysattreq))
    (and systxteva (setvar "TEXTEVAL" systxteva))
    (setq sysattdia nil)
    (setq sysattreq nil)
    (setq systxteva nil)
  )

  ;;  Start Here  -----------------
  (setq sysattdia (getvar "ATTDIA"))
  (setq sysattreq (getvar "ATTREQ"))
  (setq systxteva (getvar "TEXTEVAL"))
  (setvar "ATTDIA" 0)
  (setvar "ATTREQ" 1)
  (setvar "TEXTEVAL" 0)


 
  ;|
  '(("R1"  "X coordinate" "Y coordinate" "Z coordinate"  "Rotation"
     "X Scale"  "Y Scale"  "Z Scale"  "Layer"  "Attribute 1" "Attribute 2")
    ("R2" "6" "12" "0" "0" "1" "1" "1" "2" "AB" "100")
    ("R3" "12" "6" "0" "90" "2" "2" "2" "3" "GE" "200"))
    |;
  (setq BlkName "MyBlockName")
  (setq Alldata
         (GetExcel "C:\\Documents and Settings\\dguenthner\\My Documents\\Attribute Info.xlsx" nil nil))
  (print data)
  (foreach data AllData
    (command "-INSERT" BlkName
     "X" (nth 5 data) "Y" (nth 6 data) "Z" (nth 7 data)
     "_none"  (list (nth 1 data)(nth 2 data)(nth 3 data))
     (nth 4 data)  ; Rotation angle (optional; default = 0)
     (nth 9 data)
     (nth 10 data)
    )
     
    (command "_.chprop" (entlast) "" "LA" (nth 8 data) "")
     
  )
  (CloseExcel nil)
  (princ)
)
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.

HofCAD

  • Guest
Re: Inserting Block, but reading from Excel
« Reply #16 on: January 19, 2010, 12:30:10 PM »
hofCAD,

Thanks for your suggestion.  Unfortunately, I couldn't get the attribute values entered into the block's attribute.  After reviewing AutoCAD's commandline, I noticed the attribute values were being called, but AutoCAD couldn't locate a command.  So after the rotation values was supplied the insert command ended and the attribute value was entered at the command prompt.  Do I have to adjust something in AutoCAD to get the insert command to recognize the following attributes?

BTW I had a difficult time reading the comments.  What language was the vba written in?
Thanks, Debbie  
Debbie,

Did you use the drawing HappyTot.dwg with the block Happy
with 2 attribute definitions?
Is at your local settings the decimal point separator a dot?

The macros in HappyBlok.xls are not really written in VBA,
but in Excel Dynamic Data Exchange (DDE) Macro language.
http://www.exceldde.com/
Some comment is made in Dutch.

Regards HofCAD CSI.

PS For 'Drawing a Helix Spiral in AutoCAD LT' or AutoCAD
with the Dynamic Data Exchange (DDE) method see:
http://forums.augi.com/showthread.php?t=112935
or http://www.theswamp.org/index.php?topic=31206.msg368008#msg368008
For 'Need lisp routine input a data in CAD' see:
http://forums.augi.com/showthread.php?t=98100&highlight=DDE-LINES.xls+hofcad
« Last Edit: January 19, 2010, 02:42:44 PM by HofCAD »

debgun

  • Guest
Re: Inserting Block, but reading from Excel
« Reply #17 on: January 19, 2010, 10:18:08 PM »
CAB & HofCAD,

I really appreciate your help.  I got your codes to work.