Redefine only block script

Redefine only block script

lmnDCJSJ
Enthusiast Enthusiast
1,076 Views
10 Replies
Message 1 of 11

Redefine only block script

lmnDCJSJ
Enthusiast
Enthusiast

I really hope someone can help.

 

I have a lot of files, with various Dynamic blocks and normal blocks, but when I have to update some of them, it is very timeconsuming, with using Design Center, locate the file, with the correct block, select "redefine only" and then there is a ca. 10 wait, until it is updated, and that is for each block.

 

Is there a way to force the redefine only option, based on the location of the workfile, with the correct block?

 

I am currently spending 80-90% of the time, just waiting.

0 Likes
Accepted solutions (1)
1,077 Views
10 Replies
Replies (10)
Message 2 of 11

VincentSheehan
Advisor
Advisor

Would this help? It's Autodesk ScriptPro.

 

 

Here is the download of ScriptPro on Autodesk's web site.

https://www.autodesk.com/support/technical/article/caas/tsarticles/ts/7xKPXzhEGzvnF4qzy2Ddi9.html 

 

If you have access to Autodesk Batch Save Utility, it will do the same.

Vincent Sheehan

Sr. Civil Designer
Poly In 3D Blog

0 Likes
Message 3 of 11

lmnDCJSJ
Enthusiast
Enthusiast
So just to be sure, the video shows how to replace the block called title, in some files, correct?
That is for sure the mainpart for me, but my block, is within an existing file, so is it the easiest way to save that specific block (like the title block) and then run the script, so i have the option to point to a specific file?
0 Likes
Message 4 of 11

VincentSheehan
Advisor
Advisor

How I see it, write the script to replace a block then use software to run the script in each file.

Vincent Sheehan

Sr. Civil Designer
Poly In 3D Blog

0 Likes
Message 5 of 11

lmnDCJSJ
Enthusiast
Enthusiast
I have tried it, and it work in princip, but how do I write a script, that can replace a block, from a block within a different file.
If I have a File called A.dwg, and in that, there is 3 dynamic blocks, called block1, block2, block3.
In file B.dwg, I have block1 inserted, but want to redefine it, I have tried to make the same script as shown in the example with the title.dwg, and that works for a normal block, but not for a dynamic block.
""
-INSERT
TITLE=
(COMMAND \E "RESUME")
QSAVE

""
0 Likes
Message 6 of 11

Sea-Haven
Mentor
Mentor

Dynamic blocks lose their name and become "*U123" etc but they do keep their old EFFECTIVE NAME, so replacing has to check the effective name not block name, a help is that a normal block also has an effective name which is the normal block name.

 

Sorry  no code but if you use VL (vlax-get obj 'effectivename) can help.

Message 7 of 11

MrJSmith
Advocate
Advocate

Are these standard blocks or attributed blocks? I wrote something do allow mass redefining of blocks without having to open up each drawing. You can find it here: https://www.theswamp.org/index.php?topic=54041.msg603927#msg603927

0 Likes
Message 8 of 11

lmnDCJSJ
Enthusiast
Enthusiast

I have tried all of the suggestions above, and my long term go-to, will be the ScriptPro, but for some reason it dont work with my files in the specific case.
I have tested it, just as the video guide shows, an that works, then I have tested with my own testfiles, and that work too, the I tested with replacing a block, with a dynamic block, and that work too, but when I try my actual files, it keep failing, and I cant see any log files, and it states "Error while try to read error file for..."
When I use my scriptfile, by drag/drop it into a drawing, it behaves excactly as intended, but when using ScriptPro it fails.

Any ideas?

 

btw, is it possible to keep the programfile as standard, i use the coreconsole.exe

0 Likes
Message 9 of 11

paullimapa
Mentor
Mentor
Accepted solution

Give AutoScript a try

https://www.cadig.com/products/autocad-script-pro.php


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 11

lmnDCJSJ
Enthusiast
Enthusiast

I tried AutoScript, and it works, but it is not as userfriendly as ScriptPro, but it works, but I wish there was a solution to run it, without open each file

0 Likes
Message 11 of 11

paullimapa
Mentor
Mentor

Glad that worked out for you.  If you move all the dwgs you need to run the script file then into a single folder, then this lisp function DwgAccPikScr.lsp will offer you the option to select the folder, the script file & then execute using coreconsole:

; DwgAccPikScr
; Dir = Select Folder containing drawings to run
; acc = Locate AutoCAD Core Console execution file
; fs = Pick Script file 
; fn = Write Command file to run AutoCAD Core Console on Folder with Script
; 
(princ"\nLoading...")
(defun c:DwgAccPikScr (/ acc Dir Directory-Dia fn fs fw pick_scr)
 (vl-load-com) ; load vl module
;---------------------------------------------------------
;; Directory-Dia select folder gui
;---------------------------------------------------------
 (defun Directory-Dia ( Message / sh folder folderobject result)
;; bit number
;; 16 Will offer option to type a folder name but without checking if folder exist
;; 0,64 Will offer option to Make New Folder
;; 512 no folder name entry and no make new folder button
  (setq sh(vla-getInterfaceObject (vlax-get-acad-object)"Shell.Application"))
  (setq folder
   (vlax-invoke-method
    sh
    'BrowseForFolder
    (vla-get-HWND (vlax-get-Acad-Object))
    Message
    512 ; bit number 
    0 ; This specifies top folder tree if letter ie "C:"=drive if drive letter does not exist will default to Desktop
      ; or if #, then the following:
      ; # 0=Desktop, 1=The Internet, 2=Programs, 3=AllControlPanel, 4=Printers, 5=Documents, 6=Favorites
      ; 7=Startup, 8=RecentItems, 9=SendTo, 10=RecycleBin, 11=StartMenu, 17=ThisPC, 18-Network
   )
  ) ; setq
  (vlax-release-object sh)
  (if folder
   (progn
    (setq folderobject (vlax-get-property folder 'Self))
    (setq result (vlax-get-property FolderObject 'Path))
    (vlax-release-object folder)
    (vlax-release-object FolderObject)
    (if (/= (substr result (strlen result)) "\\")
     (setq result (strcat result "\\"))
     result
    ) ; if
   ) ; progn
  ) ; if
 ) ; defun
;---------------------------------------------------------
;; pick_scr select file using express or vanilla lisp gui 
;---------------------------------------------------------
 (defun pick_scr (title filePath Extension)
  (if(and(member "acetutil.arx"(arx))acet-ui-getfile)
   (acet-ui-getfile title filePath Extension "" 288)
   (getfiled title filePath Extension 8)
  )
 ) ; defun
;---------------------------------------------------------
; Main Program
;---------------------------------------------------------
 (if 
  (and
   (setq Dir (Directory-Dia "Select Drawing Folder to Process Script:"))
   (setq acc (findfile"AcCoreConsole.exe"))
   (setq fs (pick_scr "Select Script File" Dir "scr")) ; pick script file
  )
  (progn
   (setq fn (vl-filename-mktemp "DwgAccPikScr.cmd"))
   ; write batch file
   (if
    (and 
     (findfile fs)
     (setq fw (open fn "w"))
    )
    (progn
     (write-line 
      (strcat
       "FOR %%f in " 
       (chr 40)
       "\""
        Dir
       "*.dwg"
       "\""
       (chr 41) 
       " DO "
       "\""
       acc 
       "\""
       " /i \"%%f\" /s "
       "\""
       fs
       "\""
       " /l en-US"
      )
      fw
     )
     (close fw)
     (princ(strcat"\n...Processing Coreconsole on Folder: [" Dir "]..."))
     (startapp fn) ; launch coreconsole to run script on all dwgs in folder
     (startapp "explorer.exe" (strcat "/root," Dir))  ; open folder location to review results
    ) ; progn
   ) ; if
; cannot delete cmd file in temp folder because is still processing
;   (vl-file-delete fn) 
  ) ; progn 
  (alert"DwgAccPikScr Command Cancelled.")
 ) ; if
 (princ)
) ; defun
(princ"\nDwgAccPikScr loaded successfully.")(princ)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes