Jump to content

Block Attribute Update


CADEveryDay

Recommended Posts

I am trying to create a lisp that will update a title block 'SNP-00A1AH00PW'

I have a block named "SNP-00A1AH00PW".

There are 2 specific attributes which I want to change in it.

The attribute names are...

TITLE1 & TITLE2

TITLE1 will = SIP
TITLE2 will = STAGE_2

I have currently put together the following. However, this does not seem to work. Any help would be appreciated.

 

(defun c:updateblock (block-name / SNP-00A1AH00PW)
  (setq ss (ssget "_X" '((0 . "INSERT") (2 . SNP-00A1AH00PW))))
  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (ssname ss i))
        (setq atts (entget ent))
        (foreach att atts
          (if (= "ATTRIB" (cdr (assoc 0 att)))
            (progn
              ; Update attribute values here
              ; For example, to update the value of an attribute named "TITLE1" to "20"
              ; Replace "TITLE1" and "20" with your desired values
              (cond ((= "TITLE1" (cdr (assoc 2 att))) 
                      (setq att-value "SIP")
                      (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                    ((= "TITLE2" (cdr (assoc 2 att))) 
                      (setq att-value "STAGE_2")
                      (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                    )
            )
          )
        )
        (setq i (+ i 1))
      )
    )
  )
)

 

Edited by SLW210
Added Tags!
Link to comment
Share on other sites

If this is a title block I don't know if setpropertyvalue works on another tab. and I can't test since it only works in AutoCAD. its also only asking once and setting all the attributes to the same thing. I have code on here that will zoom to the block in question and ask for input. if that is more what your looking for.

 

;;----------------------------------------------------------------------------;;
;; Update Block's Attributes
;; mhupp 09/27/23 https://www.cadtutor.net/forum/topic/78389-block-attribute-update/
(defun c:UB (/ SS T1 T2)
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . SNP-00A1AH00PW))))
    (progn
      (setq T1 (getstring "Title: " T))
      (setq T2 (getstring "Title2: " T))
      (foreach blk (mapcar 'cadr (ssnamex ss))
        (setpropertyvalue blk "TITLE1" T1)
        (setpropertyvalue blk "TITLE2" T2)
      )
      (prompt (strcat "\n" (itoa (sslength ss)) " Blocks updated")
    )
    (prompt "\nBlock SNP-00A1AH00PW Not Found")
  )
  (princ)
)

 

 

 

 

Link to comment
Share on other sites

The idea is to run this routine on startup when opening drawings without requiring user input in AutoCAD. 

each time I use it I would like to update the required fields within the lisp and open the drawings on Autocad.

 

I will then finish the routine with <(vl-cmdf "close" "NO")> 

 

Thanks for the help so far.

Link to comment
Share on other sites

A more global approach would be select a block then pop a dcl with the tag names, select the ones to change, the next step would pop a new dcl with those tag names and current values, change or accept values. Then update all.

 

For those who follow me multi toggles supports about 20 toggles vertically or Lee-mac list box choose supports more, my old title block had 20 atts. Then use multi getvals. This is Tagname and attribute value. Some values you can see are blank and need to be filled in.

 

image.png.95d0f5e277b335a0aa25f094cfe604f0.png

 

For any one.

 

(if (not AH:Toggs)(load "Multiple toggles.lsp"))
(setq obj (vlax-ename->vla-object (car  (entsel "Pick Block "))))
(setq atts (vlax-invoke obj 'Getattributes))
(setq lst '())
(setq lst (cons "Please choose " lst))
(foreach att atts
(setq tagname (vlax-get att 'tagstring))
(setq tagval (vlax-get att 'textstring))
(setq str (strcat tagname "   " tagval))
(setq lst (cons str lst))
)
(setq ans (reverse  (ah:toggs (reverse lst))))
; look in ans it has 0 or 1 for multi toggles you picked = 1 compare to lst list.
("0" "0" "0" "1" "0" "0" "0" "0" "1" "1" "0" "0" "0" "1" "0" "0" "0" "0" "0" "0")

Will think about part 2 enter matching values. Could do in one dcl, 2 columns.

Multi toggles.lsp

Edited by BIGAL
Link to comment
Share on other sites

Lee Mack has a similar lisp to what I'm looking for, however, it still requires user input. (see below code)

 

(defun c:attchange ( / i l s x )
    ;; Define function, declare local variable symbols.
    ;; To understand why variable declaration is important, see http://bit.ly/15Qw104
    
    (if ;; If we can retrieve a set of attributed blocks
        (setq s ;; Assign the selection set pointer to variable 's'
            (ssget "_X" ;; Search entire database (see http://bit.ly/137NmOJ for more info)
               '(
                    (0 . "INSERT") ;; Block References
                    (66 . 1) ;; Attributed
                    (2 . "WD_MLRH") ;; with name WD_MLRH (this assumes block is non-dynamic)
                )
            ) ;; end SSGET
        ) ;; end SETQ
        (progn
            ;; Evaluate the following expressions and return the result
            ;; of the last expression evaluated. PROGN is used as a
            ;; wrapper function so that we can pass multiple expressions
            ;; to the IF function as a single argument constituting the
            ;; 'then' parameter.
            
            (initget 6) ;; (+ 2 4): 2=prevent zero, 4=prevent negative
            (if (setq x (getreal "\nEnter first rung number: ")) ;; Prompt user for rung number > 0
                (progn
                    ;; See above explanation for PROGN

                    ;; Construct an association list of attribute tags & values
                    ;; to pass to the LM:setattributevalues function
                    (setq l
                        (cons
                            (cons "RUNGFIRST" (itoa (fix x))) ;; => e.g. ("RUNGFIRST" . "2")

                            ;; Use a quoted literal list for the remaining tags/values
                            ;; as there are no expressions to be evaluated.
                            ;; For an explanation of the apostrophe, see http://bit.ly/1bW3rQK
                           '(
                                ("RUNGCNT"  . "20")
                                ("RUNGDIST" .  "1")
                            )
                        ) ;; end CONS
                    ) ;; end SETQ
                    
                    ;; The resulting list might look like this:
                    ;; l = (("RUNGFIRST" . "2") ("RUNGCNT"  . "20") ("RUNGDIST" .  "1"))
                
                    ;; Repeat the following expressions a number of times
                    ;; equal to the number of items in the selection set.
                    ;; Note that the numerical argument for the repeat function
                    ;; is only evaluated once and hence the integer index variable 'i'
                    ;; will only be assigned a value once.
                    (repeat (setq i (sslength s))

                        ;; Call the LM:setattributevalues function with the block entity name
                        ;; and association list of attribute tags/values to be set.
                        (LM:SetAttributeValues (ssname s (setq i (1- i))) l)
                    ) ;; end REPEAT
                ) ;; end PROGN
            ) ;; end IF
        ) ;; end PROGN

        ;; Else no blocks were found...
        (princ "\nNo \"WD_MLRH\" blocks were found.")
    ) ;; end IF
    
    (princ) ;; Supress the return of the last evaluated expression
) ;; end DEFUN


;; Set Attribute Values  -  Lee Mac
;; Sets the block attributes whose tags are found in the supplied
;; assocation list to their associated values.
;; Arguments:
;; blk - [ent] Block (Insert) Entity Name
;; lst - [lst] Association list of ((<TAG> . <Value>) ... )
;; Returns: nil

(defun LM:SetAttributeValues ( blk lst / enx itm )
    (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
        (if (setq itm (assoc (strcase (cdr (assoc 2 enx))) lst))
            (progn
                (if (entmod (subst (cons 1 (cdr itm)) (assoc 1 enx) enx))
                    (entupd blk)
                )
                (LM:SetAttributeValues blk lst)
            )
            (LM:SetAttributeValues blk lst)
        )
    )
)

(princ) ;; Suppress the return of any loading expressions

 

As the block name and attribute tags will be constant, I ideally would turn the lisp on or off via the text editor and drag and drop the necessary drawings into CAD. 

 

thus, requiring no input or command to be invoked for it to run. 

 

like this simple lisp.

 

<;Purge, Audit & Zoom Extents
(defun MacroWD01 ()
(COMMAND "FILEDIA" "0")
(COMMAND "PURGE" "ALL" "" "NO")
(COMMAND "AUDIT" "YES")
(COMMAND "ZOOM" "EXTENTS")
)>

Thanks for the help so far.

Edited by CADEveryDay
Link to comment
Share on other sites

You may be trying to update anonymous blocks instead of uniquely named blocks. In that case, using LM:al-effectivename from Lee Mac is really useful for filtering your block selections when using SSGET. I have a block filter I wrote with some input from the AutoLISP experts:

;********************************************************;
; Block Name Filter 
; ss [selection-set] from ssget
; blknamelist [list] - list of [str] of effective block names to filter (e.g. "SNP-00A1AH00PW")
; ss_new [selection-set] - Filtered selection set of ssnames of blocks
; Usage: (MA:block_filter (ssget "_X" '((0 . "INSERT"))) (list "SNP-001AH00PW"))
(defun MA:block_filter (ss blknamelist / count i ent obj ss_new) 
  (if ss 
    (progn 
      (setq ss_new (ssadd))
      (setq count (sslength ss))
      (setq i -1)
      (repeat count 
        (setq ent (ssname ss (setq i (1+ i))))
        (setq obj (vlax-ename->vla-object ent))
        (foreach blkname blknamelist 
          (if 
            (or 
              (wcmatch (strcase (LM:al-effectivename ent) T) 
                       (strcat "*" blkname "*")
              )
              (= blkname (LM:al-effectivename ent))
            )
            (ssadd ent ss_new)
          )
        )
      )
      ss_new
      ;(sssetfirst nil ss_new) ; Can be used to see which entities are highlighted
    )
  )
)
;********************************************************;
;; Effective Block Name  -  Lee Mac
;; ent - [ent] Block Reference entity
(defun LM:al-effectivename (ent / blk rep) 
  (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**") 
    (if 
      (and 
        (setq rep (cdadr 
                    (assoc -3 
                           (entget 
                             (cdr 
                               (assoc 330 
                                      (entget 
                                        (tblobjname "block" blk)
                                      )
                               )
                             )
                             '("AcDbBlockRepBTag")
                           )
                    )
                  )
        )
        (setq rep (handent (cdr (assoc 1005 rep))))
      )
      (setq blk (cdr (assoc 2 (entget rep))))
    )
  )
  blk
)

 

Insert the functions above at the end of your lsp file. 

 

In your first line in the c:updateblock, replace it with this:

  (setq ss (MA:block_filter (ssget "_X" '((0 . "INSERT"))) (list "SNP-001AH00PW")))

 

You can always test if your blocks have anonymous names by using (cdr (assoc 2 (entget (car (entsel))))) in AutoCAD in the command line and you select the block.

Link to comment
Share on other sites

Try this, change the lists in 'values' as required, the loop later on works by the Final_values list, if Final_Destination list is shorter than that there could be problems. You could check for that in the code though

 

(defun c:test ( / Tag Val Blk acount)
;;Values
(setq Final_Block "MyBlock") ; Block Name
(setq Final_Value (list "Value 1" "Value 2")) ; can increase this as required
(setq Final_Destination (list "Tag1" "Tag2")) ; can increase this as required

;; Sub Functions
  (defun LM:setattributevalues ( blk lst / enx itm )
    (while (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if
            (and
                (setq itm (assoc (cdr (assoc 2 enx)) lst))
                (entmod (subst (cons 1 (cdr itm)) (assoc 1 (reverse enx)) enx))
            )
            (entupd blk)
        )
    )
    nil
  )

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Val))
        (setq Tag (nth 1 Final_Destination))
        (setq Val (nth 1 Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
)

 

  • Like 1
Link to comment
Share on other sites

On 9/28/2023 at 1:39 AM, Emmanuel Delay said:

You can automatically load lisp files.

 

https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Automatically-load-AutoLISP-routines.html

 

And to auto execute a function (for example c:updateblock) you end the file with

 

(c:updateblock)

 

I literally had no idea you could do this way back a few months ago. I kept using APPLOAD to get my LISP routines working. Now, too much automation is bad, I still need to have some control instead of drawings automatically doing god knows what so I instead opted for creating my own ribbon for AutoCAD that has buttons for loading and executing LISP routines. I have my own CUI that has all my routines as buttons for AutoCAD and it is glorious.

Link to comment
Share on other sites

Look into Autoload command it allows you to type in a command that is linked to a lisp but it loads the lisp for you. Similar to a menu option.

 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "COVER" '("COVER"))
(autoload "DIMFLIP" '("DIMFLIP"))

 

Are you using pop menu's or toolbars, you can write those external to the cui as custom mnu's just use notepad. The ribbon need to use cui.

image.png.71defd3842b7845ed29d1394ceb784ac.png

 

Link to comment
Share on other sites

On 10/6/2023 at 6:09 AM, Steven P said:

Try this, change the lists in 'values' as required, the loop later on works by the Final_values list, if Final_Destination list is shorter than that there could be problems. You could check for that in the code though

 

(defun c:test ( / Tag Val Blk acount)
;;Values
(setq Final_Block "MyBlock") ; Block Name
(setq Final_Value (list "Value 1" "Value 2")) ; can increase this as required
(setq Final_Destination (list "Tag1" "Tag2")) ; can increase this as required

;; Sub Functions
  (defun LM:setattributevalues ( blk lst / enx itm )
    (while (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if
            (and
                (setq itm (assoc (cdr (assoc 2 enx)) lst))
                (entmod (subst (cons 1 (cdr itm)) (assoc 1 (reverse enx)) enx))
            )
            (entupd blk)
        )
    )
    nil
  )

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Val))
        (setq Tag (nth 1 Final_Destination))
        (setq Val (nth 1 Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
)

 

This is what I'm looking for however, this seems to return the following when the command 'test' is invoked.

Command: test
nil
Command:

I have filled out the .lsp file and checked the block name is correct see below.

(defun c:test ( / Tag Val Blk acount)
;;Values
(setq Final_Block "SNP-00A1AH00PW") ; Block Name
(setq Final_Value (list "999" "test")) ; can increase this as required
(setq Final_Destination (list "TITLE1" "TITLE2")) ; can increase this as required

;; Sub Functions
  (defun LM:setattributevalues ( blk lst / enx itm )
    (while (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if
            (and
                (setq itm (assoc (cdr (assoc 2 enx)) lst))
                (entmod (subst (cons 1 (cdr itm)) (assoc 1 (reverse enx)) enx))
            )
            (entupd blk)
        )
    )
    nil
  )

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Val))
        (setq Tag (nth 1 Final_Destination))
        (setq Val (nth 1 Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
)

Thanks for your help so far.

Link to comment
Share on other sites

Need a dwg to test on but hopefully this makes sense.

 

(progn
   (repeat (setq x (sslength blk))
   (setq blkitem (ssname blk (setq x (1- x))))
   (setq Tag (nth 0 Final_Destination))
   (setq Val (nth 0 Final_Value))
   (lm:setattributevalue blkitem Tag Val)
   (setq Tag (nth 1 Final_Destination))
   (setq Val (nth 1 Final_Value))
   (lm:setattributevalue blkitem Tag Val)
	)
)

Just a PS I would make the Blkitem a vl object and just update the attribute via its order in the attributes. Like say 3 & 5.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

6 hours ago, CADEveryDay said:

This is what I'm looking for however, this seems to return the following when the command 'test' is invoked.

Command: test
nil
Command:

I have filled out the .lsp file and checked the block name is correct see below.

(defun c:test ( / Tag Val Blk acount)
;;Values
(setq Final_Block "SNP-00A1AH00PW") ; Block Name
(setq Final_Value (list "999" "test")) ; can increase this as required
(setq Final_Destination (list "TITLE1" "TITLE2")) ; can increase this as required

;; Sub Functions
  (defun LM:setattributevalues ( blk lst / enx itm )
    (while (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if
            (and
                (setq itm (assoc (cdr (assoc 2 enx)) lst))
                (entmod (subst (cons 1 (cdr itm)) (assoc 1 (reverse enx)) enx))
            )
            (entupd blk)
        )
    )
    nil
  )

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Val))
        (setq Tag (nth 1 Final_Destination))
        (setq Val (nth 1 Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
)

Thanks for your help so far.

 

 

Yes, nil is OK here - that is the result of the last thing the routine evaluates (an if in the while loop), put a (princ) before the last bracket ')' in the code for it to exit quitly

Link to comment
Share on other sites

On 10/7/2023 at 7:13 PM, BIGAL said:

Need a dwg to test on but hopefully this makes sense.

 

(progn
   (repeat (setq x (sslength blk))
   (setq blkitem (ssname blk (setq x (1- x))))
   (setq Tag (nth 0 Final_Destination))
   (setq Val (nth 0 Final_Value))
   (lm:setattributevalue blkitem Tag Val)
   (setq Tag (nth 1 Final_Destination))
   (setq Val (nth 1 Final_Value))
   (lm:setattributevalue blkitem Tag Val)
	)
)

Just a PS I would make the Blkitem a vl object and just update the attribute via its order in the attributes. Like say 3 & 5.

Please see attached for the block this code is intended for.

 

Also thank you very much for the help.

EG.dwg

Link to comment
Share on other sites

On 10/7/2023 at 2:46 AM, CADEveryDay said:

This is what I'm looking for however, this seems to return the following when the command 'test' is invoked.

I have filled out the .lsp file and checked the block name is correct see below.

Thanks for your help so far.

 

Had a check with the sample drawing you posted - I haven't done so well here, missed a couple of things in the code above, here is a better version, try this

 

You'll have to change the Final_Values list to be as you want (I have left it like that on purpose by the way)

 

I've also split the LISP into 2 parts, a 'wrapper' to run the main part and the main part. You could if you want create some new wrappers with different blocks, tags, values as you want for different block updates. So I might have one "UpdTitle" (update title block) as below, I might have one "UpdRevs (update rev blocks) to put the drawn, checked and approved names on a drawing and "UpdClient1" to add that client details to a title block

 

(defun c:test ( / Final_Block Final_Destination Final_Value)
;;Values
  (setq Final_Block "SNP-00A1AH00PW")               ; Block Name
  (setq Final_Destination (list "TITLE1" "TITLE2")) ; Tags to change. Can add to this list
  (setq Final_Value (list "value 2" "value 3"))     ; new values of tags, to match tag names above

  (spupdatetags Final_Block Final_Destination Final_Value) ; Run next function passing the values above to it
  (princ)
)
(defun spupdatetags ( Final_Block Final_Destination Final_Value /  Tag Val Blk acount)
;; Sub Functions
  (defun LM:setattributevalue ( blk tag val / end enx )
    (while
        (and
            (null end)
            (setq blk (entnext blk))
            (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk)))))
        )
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                (progn
                    (entupd blk)
                    (setq end val)
                )
            )
        )
    )
  ) ; end defun

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Final_Value))
        (setq Tag (nth acount Final_Destination))
        (setq Val (nth acount Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
  (princ "OK, tags changed")(princ)
)

 

Edited by Steven P
Link to comment
Share on other sites

A more global approach pick a block a custom dcl is needed. I need to combine my multi Toggle with multi getval.

image.png.c25e659ca5f5c0d97dae86ed8a92dc71.png

 

Added to my to do list.

 

Edited by BIGAL
Link to comment
Share on other sites

On 10/9/2023 at 9:33 PM, Steven P said:

 

Had a check with the sample drawing you posted - I haven't done so well here, missed a couple of things in the code above, here is a better version, try this

 

You'll have to change the Final_Values list to be as you want (I have left it like that on purpose by the way)

 

I've also split the LISP into 2 parts, a 'wrapper' to run the main part and the main part. You could if you want create some new wrappers with different blocks, tags, values as you want for different block updates. So I might have one "UpdTitle" (update title block) as below, I might have one "UpdRevs (update rev blocks) to put the drawn, checked and approved names on a drawing and "UpdClient1" to add that client details to a title block

 

(defun c:test ( / Final_Block Final_Destination Final_Value)
;;Values
  (setq Final_Block "SNP-00A1AH00PW")               ; Block Name
  (setq Final_Destination (list "TITLE1" "TITLE2")) ; Tags to change. Can add to this list
  (setq Final_Value (list "value 2" "value 3"))     ; new values of tags, to match tag names above

  (spupdatetags Final_Block Final_Destination Final_Value) ; Run next function passing the values above to it
  (princ)
)
(defun spupdatetags ( Final_Block Final_Destination Final_Value /  Tag Val Blk acount)
;; Sub Functions
  (defun LM:setattributevalue ( blk tag val / end enx )
    (while
        (and
            (null end)
            (setq blk (entnext blk))
            (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk)))))
        )
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                (progn
                    (entupd blk)
                    (setq end val)
                )
            )
        )
    )
  ) ; end defun

  (if (= (setq blk (ssget "_X" (list (cons 2 Final_Block)))) nil)
    (progn
      (princ "Block Not Found")
    )
    (progn
      (setq blk (ssname blk 0))
      (setq acount 0)
      (while (< acount (length Final_Value))
        (setq Tag (nth acount Final_Destination))
        (setq Val (nth acount Final_Value))
        (lm:setattributevalue blk Tag Val)
        (setq acount (+ acount 1))
      )
    )
  )
  (princ "OK, tags changed")(princ)
)

 

Thanks for this it works well, however, it requires the user to invoke the command 'test' in the drawing. The idea was to update the lsp in a text editor, save it and drag and drop the relevant drawings into CAD. In this form the .lsp wont allow me to do this. I was thinking I could edit the first line to achieve this, see below code.

(defun Macro01 ( / Final_Block Final_Destination Final_Value)

Unfortunately, this does not work. any suggestions would be appreciated.

Link to comment
Share on other sites

Yes, rename it as you want, Macro01 will work as well as anything else. The c before the lisp name just lets it be used in the command line (could rename it c:Macro01).

It should work if you put this line at the end of the code - after the last bracket, )

(Macro01)

 

So the LISP file will load into CAD and when it reaches the (Macro01) line will run it

 

As for dragging and dropping, a lot of time I find it quicker to use the keyboard, so dragging and dropping or typing Macro01 will take a similar length of time, you could add the LISP file to the start-up suit (appload - startup suit), without the (Macro01) line of course else it will run on every file you load, and go that way. Update the LISP file, save, load the drawings and the LISP should also be loaded (probably telling you what you all ready know).

 

For this I also have this, so you can load a modified LISP file easier (they will load when the drawing is opened but but be updated unless you tell it to), add your Macro01 and file path below, modify as required, 'appreload' in any open drawings (once per drawing) and 'Macro01'

 

(defun c:appreload ( / )
  (load "c:\\filepath\\misc.lsp" "misc Lisp Failed to Load")
  (princ "OK")(princ)
)

 

Link to comment
Share on other sites

I have 1 lisp called autoload.lsp loaded to the Start up suite so loads on opening Autocad/Bricscad it has 10 (load "????") as well as 12 "Autoload" 23 defuns. The Autoload has advantage it loads when you type the command.

 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "COVER" '("COVER"))

 

So add your samll defuns to that then ready to go, big defuns use (load.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...