Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 11 of 22 (605 Views)

Re: Update blocks & attributes LISP

09-06-2013 07:30 AM in reply to: Klingi162

Klingi162 wrote:

thanks, but no change. :smileysad:

It just writes "Unable to locate block: I:\\AutoCAD block Library\testblock.dwg


 

This would indicate that there is no drawing with filename testblock.dwg residing within the directory I:\AutoCAD block Library - can you confirm that this drawing is present?

 

Have you altered the program in any way?

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Distinguished Contributor
bhull1985
Posts: 417
Registered: ‎07-17-2013
Message 12 of 22 (599 Views)

Re: Update blocks & attributes LISP

09-06-2013 12:26 PM in reply to: Lee_Mac

Well there's also two \\ after I: and then there's only one \ after Block Library

Maybe that is why..

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Valued Contributor
Klingi162
Posts: 73
Registered: ‎09-05-2013
Message 13 of 22 (568 Views)

Re: Update blocks & attributes LISP

09-10-2013 06:20 AM in reply to: Lee_Mac

I didn't change anything from your file...well I changed the filepath to a new location, just to try if this makes any change.

The new blocklibrary is now " I:\AutoCAD Blöcke\template\"

 

this is what appeared when i run the LISP:

 

Befehl: REDEFALL

Unable to locate block: I:\AutoCAD Blöcke\template\Adler.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\adler logo.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\Bemassungsstricherl.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\A$C553C1C71.dwg
Regeneriert Layout.
Regeneriert Modell.

 

so I opend a new file to be sure that I didn't miss any blocks and just inserted one specific block. now only this appears:

 

Befehl: redefall

Regeneriert Modell.

 

so far so good, but it still doesn't update any changes from this one block file...

so when I for example add some lines in the block and save it and then I run the Lisp in the file where I inserted this specific block and no lines show up.

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 14 of 22 (558 Views)

Re: Update blocks & attributes LISP

09-10-2013 10:16 AM in reply to: Klingi162

Klingi162 wrote:

this is what appeared when i run the LISP:

 

Befehl: REDEFALL

Unable to locate block: I:\AutoCAD Blöcke\template\Adler.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\adler logo.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\Bemassungsstricherl.dwg
Unable to locate block: I:\AutoCAD Blöcke\template\A$C553C1C71.dwg


 

Can you confirm that the drawing files (Adler.dwg / adler logo.dwg / etc.) are present in the folder I:\AutoCAD Blöcke\template?

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
Klingi162
Posts: 73
Registered: ‎09-05-2013
Message 15 of 22 (531 Views)

Re: Update blocks & attributes LISP

09-12-2013 07:51 AM in reply to: Lee_Mac

I already changed it, so all the blocks are present.

 

still this:

 

Befehl: redefall


Regeneriert Layout.
Regeneriert Modell.

 

nothing else shows up. I already tried everything, but won't work. :smileysad:

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 16 of 22 (521 Views)

Re: Update blocks & attributes LISP

09-12-2013 08:51 AM in reply to: Klingi162

Klingi162 wrote:

I already changed it, so all the blocks are present.

 

still this:

 

Befehl: redefall


Regeneriert Layout.
Regeneriert Modell.

 

nothing else shows up. I already tried everything, but won't work. :smileysad:


I'm not really sure what else to suggest... :smileyfrustrated:

 

Providing that there are non-anonymous block definitions in your drawing, you should be receiving some messages whether the blocks can be found or not...

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
Klingi162
Posts: 73
Registered: ‎09-05-2013
Message 17 of 22 (510 Views)

Re: Update blocks & attributes LISP

09-12-2013 11:55 PM in reply to: Lee_Mac

Hey Lee,

 

I found one of your old scripts in an other forum and this one works perfectly. It doesn't do the whole trick but maybe you can help me to add the last step. The only thing thats missing is the part that say to replace every block from a specific folder path. Now it just replaces only the blocks that I really put in one by one...

The Rest works great...half way there!!! :smileyhappy:

 

Thats your Code:

 

(defun c:ReDef ( / *error* oc spc doc block b )
(vl-load-com)
;; © Lee Mac 2010

;; Full filename needed if block is not in the support path
(setq BlocksToRedefine
'(
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A0.dwg"
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A1.dwg"
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A2.dwg"
)
)

(defun *error* ( msg )
(and oc (setvar 'CMDECHO oc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)

(setq spc
(vlax-get (vla-get-ActiveDocument (vlax-get-acad-object))
(if (= 1 (getvar 'CVPORT)) 'PaperSpace 'ModelSpace)
)
)

(setq oc (getvar 'CMDECHO)) (setvar 'CMDECHO 0)

(foreach block BlocksToRedefine
(if (setq b (findfile (strcat block (if (not (vl-filename-extension block)) ".dwg" ""))))
(progn
(vla-delete
(vla-insertblock spc
(vlax-3D-point '(0. 0. 0.)) b 1. 1. 1. 0.
)
)
(vl-cmdf "_.attsync" "_N" (vl-filename-base b))
)
(princ (strcat "\n** Cannot Find Block: " block " **"))
)
)

(setvar 'CMDECHO oc)
(princ)
)

 

If you could tell me which part I have to replace everything works like a miracle

 

Thx already for your great help Lee! 

*Expert Elite*
Lee_Mac
Posts: 1,109
Registered: ‎12-29-2009
Message 18 of 22 (502 Views)

Re: Update blocks & attributes LISP

09-13-2013 03:14 AM in reply to: Klingi162

Klingi162 wrote:

'(
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A0.dwg"
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A1.dwg"
"I:\\AutoCAD Blöcke\\Template\\Support\\__Ausführung_A2.dwg"
)


 

Now I see that your block names start with underscores - the previous program was excluding any blocks with an underscore prefix (since these are usually dimension style blocks).

 

Try the following code:

 

;; Redefine All Blocks  -  Lee Mac
(defun c:redefall ( / bln dir doc dwg lst obj org spc )

    (setq dir "I:\\AutoCAD Blöcke\\Template\\Support") ;; Directory of Block Library; nil to use Support Path

    (if dir
        (setq dir (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) "\\"))
        (setq dir "")
    )
    (cond
        (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
            (princ "\nCurrent layer locked.")
        )
        (   (setq doc (vla-get-activedocument (vlax-get-acad-object))
                  spc (vla-get-modelspace doc)
                  org (vlax-3D-point 0 0)
            )
            (terpri)
            (vlax-for blk (vla-get-blocks doc)
                (if
                    (and
                        (= :vlax-false (vla-get-isxref blk))
                        (= :vlax-false (vla-get-islayout blk))
                        (not (wcmatch (setq bln (vla-get-name blk)) "`**,*|*"))
                    )
                    (if (setq dwg (findfile (strcat dir bln ".dwg")))
                        (progn
                            (princ (strcat "Redefining block: " dwg "\n"))
                            (setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0))
                            (if (= :vlax-true (vla-get-hasattributes obj))
                                (setq lst (vl-list* "," bln lst))
                            )
                            (vla-delete obj)
                        )
                        (princ (strcat "Unable to locate block: " dir bln ".dwg\n"))
                    )
                )
            )
            (if lst
                (progn
                    (princ "Synchronising attributes for redefined blocks...\n")
                    (vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))
                )
            )
            (textscr)
            (vla-regen doc acallviewports)
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
Klingi162
Posts: 73
Registered: ‎09-05-2013
Message 19 of 22 (488 Views)

Re: Update blocks & attributes LISP

09-24-2013 06:58 AM in reply to: Lee_Mac

Hey Lee Mac,

 

I didn't look in the forum for quite a while and just noticed, that you already answered a while a go. 

Your new script works like a miracle (whouldn't expect different :smileywink: ), thanks a lot for that. It does exactly what it should do. :smileyhappy:

 

I appreciate that.

I'm going to donate on your site and hope you keep on going to help us Neebies!

 

Cheers Klingi

Active Contributor
CADbloke
Posts: 37
Registered: ‎08-12-2008
Message 20 of 22 (129 Views)

Re: Update blocks & attributes LISP

06-04-2014 04:53 PM in reply to: Lee_Mac

This is brilliant ... but the ATTYNC part didn't work for me until I changed these parts ...

 

-      (setq lst (vl-list* "," bln lst))
+     (setq lst (vl-list* bln lst))

 ...and ...

- (vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))

+++
(foreach blk lst (vl-cmdf "_.attsync" "_N" blk)
);foreach

 ... and , of course, added "blk" to the locals declaration at the top of the file.

 

Thanks for writing the Lee, you're a Leegend. :smileywink:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community