Jump to content

Recommended Posts

3dwannab

Hi all,

 

Here's a routine originally wrote by LeeMac.

 

I wanted to delete the previously inserted blocks after it's done updating them.

 

Thanks in advance. I'll wrote where the problem lies in my code.

 

(defun c:BK_Update_InsertAll_Redefine_ATTSYNCAll ( / dir doc extn spc )

   (setq extn "dwg") ;; Extension of files to Insert e.g "dwg"

   (if
       ; (setq dir (LM:DirectoryDialog (strcat "Select Directory of " (strcase extn) " Files to Insert") nil 512))

       (setq dir "W:/SS_CAD/SS_AutoCAD Block's Library/Blocks Updated/" blk "`.dwg")


       (progn
           (setq doc (vla-get-activedocument (vlax-get-acad-object))
             spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
             )
           (foreach file (vl-directory-files dir (strcat "*." extn) 1)
               (vla-insertblock spc (vlax-3D-point '(0.0 -50.0 0.0)) (strcat dir "\\" file) 1.0 1.0 1.0 0.0)
               )
           (vla-regen doc acallviewports)
           (command "ATTSYNC" "NAME" "*")

           ; NOT WORKING, I want to delete the previously inserted block.
           (vlax-delete (vlax-ename->vla-object spc))

           )
       (princ "\n*Cancel*")
       )
   (princ)
   )

Share this post


Link to post
Share on other sites
Tharwat

Hi,

 

The variable 'spc' represents the space object and not the block reference so replace the variable spc with (entlast) besides that you can use the function entdel to avoid converting the object to vla-object since its not needed later on for any use.

(entdel (entlast))

Share this post


Link to post
Share on other sites
3dwannab
Hi,

 

The variable 'spc' represents the space object and not the block reference so replace the variable spc with (entlast) besides that you can use the function entdel to avoid converting the object to vla-object since its not needed later on for any use.

(entdel (entlast))

 

Thanks Tharwat, I've done what you suggested and it errors out.

error: bad function: #<VLA-OBJECT IAcadPaperSpace 000001e97f6fa558>

 

 

My code:

(defun c:BK_Update_InsertAll_Redefine_ATTSYNCAll ( / dir doc extn entlast )

   (setq extn "dwg") ;; Extension of files to Insert e.g "dwg"

   (if
       ; (setq dir (LM:DirectoryDialog (strcat "Select Directory of " (strcase extn) " Files to Insert") nil 512))

       (setq dir "W:/SS_CAD/SS_AutoCAD Block's Library/_DM Arch Blocks (Company Master Blocks)/1508 Blocks Updated/" blk "`.dwg")


       (progn
           (setq doc (vla-get-activedocument (vlax-get-acad-object))
             entlast (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
             )
           (foreach file (vl-directory-files dir (strcat "*." extn) 1)
               (vla-insertblock entlast (vlax-3D-point '(0.0 -50.0 0.0)) (strcat dir "\\" file) 1.0 1.0 1.0 0.0)
               )
           (vla-regen doc acallviewports)
           (command "ATTSYNC" "NAME" "*")

           (entdel (entlast))

           )
       (princ "\n*Cancel*")
       )
   (princ)
   )

Share this post


Link to post
Share on other sites
Tharwat

Entlast is a function and you can not use it as variable otherwise you would have lots of error clashes so just replace it as follows:

 

This:

(vlax-delete (vlax-ename->vla-object spc))

with this:

(entdel (entlast))

Share this post


Link to post
Share on other sites
3dwannab
Entlast is a function and you can not use it as variable otherwise you would have lots of error clashes so just replace it as follows:

 

This:

(vlax-delete (vlax-ename->vla-object spc))

with this:

(entdel (entlast))

 

Silly me. I got carried away there.

 

Many thanks, Tharwat!

Share this post


Link to post
Share on other sites
Tharwat

No worries at all.

You are welcome.

Share this post


Link to post
Share on other sites
Grrr

BTW theres no vlax-delete function, you can check in VLIDE:

_$ vlax-delete
nil
_$ vla-delete
#<SUBR @00000083291f4188 vla-Delete>

 

So the correct call would be either (vla-delete ) or (vlax-invoke-method 'Delete).

Share this post


Link to post
Share on other sites
3dwannab
BTW theres no vlax-delete function, you can check in VLIDE:

_$ vlax-delete
nil
_$ vla-delete
#<SUBR @00000083291f4188 vla-Delete>

 

So the correct call would be either (vla-delete ) or (vlax-invoke-method 'Delete).

 

Thanks. So basically what you're saying is it needs an argument in the form of a ?

Share this post


Link to post
Share on other sites
Grrr
Thanks. So basically what you're saying is it needs an argument in the form of a ?

 

Yes, I guess you want to store into a variable the return of the vla-InsertBlock method, since it returns the vla-object of the inserted block.. and then use vla-Delete method on it.

Share this post


Link to post
Share on other sites
Tharwat

Good catch Grrr, :thumbsup:

Share this post


Link to post
Share on other sites
Grrr
Good catch Grrr, :thumbsup:

 

Thanks, Tharwat! Hope the OP learnt something here.. :)

Share this post


Link to post
Share on other sites
3dwannab
Thanks, Tharwat! Hope the OP learnt something here.. :)

 

Well, that could be debatable. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×