Jump to content

Script Pro Script help


Emily_83

Recommended Posts

Morning Guys

 

i was wondering if you could help me, i am after a batch Script for Scriptpro to delete a block out of multiple drawings, and then insert another in it's place at 0,0, then qsave

could anyone help me? if you need any more info let me know!!

 

Cheers

 

:DEmily:D

Link to comment
Share on other sites

Hi Emily

 

I think it is better to use Lisp instead of writing dummy codes for Script file, So you can take a start with this .

(defun c:try (/ blkNmr pt)
 (setq blkNme (getstring"\n Enter Name of Block: "))
(while (setq pt(getpoint "\nSpecify Block insertion point: "))
      (vl-cmdf "_.-insert" blkNme pt "" "" "")
 )
(princ)
)

And you can add the command Qsave and Exit to codes as well ...... agree?

 

Regards

 

Tharwat

Link to comment
Share on other sites

A few questions Emily:

 

  • Would the new block be at every instance of the old block, or would it just be at 0,0,0?

  • (Related to the above) Would the new block be inserted at 0,0,0 even if the drawing did not contain the old block?

Lee

Link to comment
Share on other sites

Hi Emily

 

I think it is better to use Lisp instead of writing dummy codes for Script file, So you can take a start with this .

(defun c:try (/ blkNmr pt)
 (setq blkNme (getstring"\n Enter Name of Block: "))
(while (setq pt(getpoint "\nSpecify Block insertion point: "))
      (vl-cmdf "_.-insert" blkNme pt "" "" "")
 )
(princ)
)

And you can add the command Qsave and Exit to codes as well ...... agree?

 

Regards

 

Tharwat

 

Good morning Tharwat,

 

thankyou for your time i will give this a go.

 

Cheers

 

Emily

Link to comment
Share on other sites

A few questions Emily:

 

  • Would the new block be at every instance of the old block, or would it just be at 0,0,0?

  • (Related to the above) Would the new block be inserted at 0,0,0 even if the drawing did not contain the old block?

Lee

 

Good Morning Lee

 

the New block is the same name as the old block, it has jsut been modified and resent to us to change over so when we insert it it will be inserted at 0,0, so yes it would be at every instance of the old block as the old block is at 0,0.

 

does that answer your question or have i confused us both even more?

 

lol

 

i need a coffee.......

 

thankyou again for you help Lee

 

Cheers

 

Emily

Link to comment
Share on other sites

That explains things better Emily, thanks - you are just redefining the block definition by the sound of it.

 

I wrote this a while back for such a purpose - there are two versions, the first offers a user prompt, the second is for use within a script.

 

(defun c:ReDef ( / *error* GetActiveSpace spc nb un )
 (vl-load-com)
 ;; Lee Mac  ~  22.04.10

 (defun *error* (msg)
   (and un (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun GetActiveSpace (doc)
   (if (or (eq AcModelSpace (vla-get-ActiveSpace doc))
           (eq :vlax-true   (vla-get-MSpace doc)))
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)))

 (setq spc (GetActiveSpace
             (setq doc (vla-get-ActiveDocument
                         (vlax-get-acad-object)))))

 (if (setq nb (getfiled "Select Block" "" "dwg" 16))
   (progn
     (setq un (not (vla-StartUndoMark doc)))

     (vla-delete (vla-insertblock spc
                   (vlax-3D-point '(0 0 0)) nb 1. 1. 1. 0.))

     (vl-cmdf "_.attsync" "_N" (vl-filename-base nb))

     (setq un (vla-EndUndoMark doc))))

 (princ))

 

(defun ReDef ( block / *error* oc spc doc block )
 (vl-load-com)
 ;; © Lee Mac  ~  21.06.10

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

 (setq spc
   (if
     (or
       (eq AcModelSpace
         (vla-get-ActiveSpace
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
       (eq :vlax-true (vla-get-MSpace doc))
     )
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)
   )
 )

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

 (if (setq block (findfile block))
   (progn
     (vla-delete
       (vla-insertblock spc
         (vlax-3D-point '(0. 0. 0.)) block 1. 1. 1. 0.
       )
     )
     (vl-cmdf "_.attsync" "_N" (vl-filename-base block))
   )
 )
 
 (setvar 'CMDECHO oc)
 (princ)
)

 

Call the above with

 

(Redef "C:\\Users\\Emily\\Block.dwg")

 

Let me know if you run into trouble,

 

Lee

Link to comment
Share on other sites

That explains things better Emily, thanks - you are just redefining the block definition by the sound of it.

 

I wrote this a while back for such a purpose - there are two versions, the first offers a user prompt, the second is for use within a script.

 

(defun c:ReDef ( / *error* GetActiveSpace spc nb un )
 (vl-load-com)
 ;; Lee Mac  ~  22.04.10

 (defun *error* (msg)
   (and un (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun GetActiveSpace (doc)
   (if (or (eq AcModelSpace (vla-get-ActiveSpace doc))
           (eq :vlax-true   (vla-get-MSpace doc)))
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)))

 (setq spc (GetActiveSpace
             (setq doc (vla-get-ActiveDocument
                         (vlax-get-acad-object)))))

 (if (setq nb (getfiled "Select Block" "" "dwg" 16))
   (progn
     (setq un (not (vla-StartUndoMark doc)))

     (vla-delete (vla-insertblock spc
                   (vlax-3D-point '(0 0 0)) nb 1. 1. 1. 0.))

     (vl-cmdf "_.attsync" "_N" (vl-filename-base nb))

     (setq un (vla-EndUndoMark doc))))

 (princ))

 

(defun ReDef ( block / *error* oc spc doc block )
 (vl-load-com)
 ;; © Lee Mac  ~  21.06.10

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

 (setq spc
   (if
     (or
       (eq AcModelSpace
         (vla-get-ActiveSpace
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
       (eq :vlax-true (vla-get-MSpace *doc))
     )
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)
   )
 )

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

 (if (setq block (findfile block))
   (progn
     (vla-delete
       (vla-insertblock spc
         (vlax-3D-point '(0. 0. 0.)) block 1. 1. 1. 0.
       )
     )
     (vl-cmdf "_.attsync" "_N" (vl-filename-base block))
   )
 )

 (setvar 'CMDECHO oc)
 (princ)
)

 

Call the above with

 

(Redef "C:\\Users\\Emily\\Block.dwg")

 

Let me know if you run into trouble,

 

Lee

 

Hi there Lee,

thankyou so much for your time and help.

though not know much about Lisp and Scripts still, i need some direction.

i have copied and pasted the 2nd option for script into notepad and then saved it as a REFDEF.lsp

then i opened a new notepad and wrote a script to run the REFDEF.lsp like so

(LOAD “O:\\Projects\\TEMP\\Emily E\\REDEF.LSP”)

REDEF

QSAVE

and i saved that as REDEF.scr

is that what i should be doing?? i have no idea as i only got scriptpro on Monday and have only created 1 easy script which was to batch purge and audit the drawings.

next question is (i know this may seem stupid) but the block i am wanting to delete and replace (or refedit) is CIVIL_TB_A1

where about in the 2nd lisp routine you supplied do i enter that??

could you possibly highlight in red where i should place it?

thankyou in advance for your help

Cheers

Emily

Link to comment
Share on other sites

Hi Emily,

 

You don't need to modify the LISPs I have posted in any way :)

 

My code assumes that the block you are replacing has the same name as that which you are replacing it with, hence just one argument is needed - the replacement block.

 

Call my second option like this:

 

(ReDef "C:\\Users\\Emily\\Block.dwg")

 

as posted in my earlier post - it is not to be called at the command line, but rather as a subfunction taking one argument: the filename of the new block. (Just as you called the LOAD function with one argument).

 

I have never used ScriptPro, so I cannot advise you on that.

 

Before using the script, test my function at the command line typing the above.

 

Lee

Link to comment
Share on other sites

apologies Lee,

 

but what do you mean "Call your second option like this"? i can see the Code you have supplied me with but where do i place that..??

 

i should have training wheels on i know.

 

Cheers

Link to comment
Share on other sites

Try typing it at the command line for example. Just as you are calling the 'load' function - treat my function as if it was any other LISP function taking arguments.

 

eg.

 

(load <filename> <onfailure>)

 

(ReDef <blockfilename>)

Link to comment
Share on other sites

Try typing it at the command line for example. Just as you are calling the 'load' function - treat my function as if it was any other LISP function taking arguments.

 

eg.

 

(load <filename> <onfailure>)

 

(ReDef <blockfilename>)

 

 

Hey there Lee,

 

thankyou very much i thought that is what you meant,

 

the problem i am getting now though is the following error

 

** Error: bad argument type: VLA-OBJECT nil **

 

any clue what that means?

 

thankyou for you help and patience

 

Cheers

 

Emily

Link to comment
Share on other sites

Hi Emily,

 

I did spot a minor typo in my second code (just updated) that would affect it if you were running it when looking through a viewport - perhaps this caused your error.

 

Lee

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...