Jump to content

Trouble with vlax-delete


3dwannab

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

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