+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 10 Pro
    Computer:
    Self-Built
    CPU:
    TR 1950X
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    Arch Technician and Arch Viz
    Discipline
    Architectural
    Details
    TBC
    Using
    AutoCAD 2019
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    192

    Default Trouble with vlax-delete

    Registered forum members do not see this ad.

    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.

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

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,249

    Default

    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.
    Code:
    (entdel (entlast))

  3. #3
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 10 Pro
    Computer:
    Self-Built
    CPU:
    TR 1950X
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    Arch Technician and Arch Viz
    Discipline
    Architectural
    Details
    TBC
    Using
    AutoCAD 2019
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    192

    Default

    Quote Originally Posted by Tharwat View Post
    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.
    Code:
    (entdel (entlast))
    Thanks Tharwat, I've done what you suggested and it errors out.
    Code:
    error: bad function: #<VLA-OBJECT IAcadPaperSpace 000001e97f6fa558>

    My code:
    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)
        )

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,249

    Default

    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:
    Code:
    (vlax-delete (vlax-ename->vla-object spc))
    with this:
    Code:
    (entdel (entlast))

  5. #5
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 10 Pro
    Computer:
    Self-Built
    CPU:
    TR 1950X
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    Arch Technician and Arch Viz
    Discipline
    Architectural
    Details
    TBC
    Using
    AutoCAD 2019
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    192

    Default

    Quote Originally Posted by Tharwat View Post
    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:
    Code:
    (vlax-delete (vlax-ename->vla-object spc))
    with this:
    Code:
    (entdel (entlast))
    Silly me. I got carried away there.

    Many thanks, Tharwat!

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,249

    Default

    No worries at all.
    You are welcome.

  7. #7
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,478

    Default

    BTW theres no vlax-delete function, you can check in VLIDE:
    Code:
    _$ vlax-delete
    nil
    _$ vla-delete
    #<SUBR @00000083291f4188 vla-Delete>
    So the correct call would be either (vla-delete <vla-object>) or (vlax-invoke-method <vla-object> 'Delete).

  8. #8
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 10 Pro
    Computer:
    Self-Built
    CPU:
    TR 1950X
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    Arch Technician and Arch Viz
    Discipline
    Architectural
    Details
    TBC
    Using
    AutoCAD 2019
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    192

    Default

    Quote Originally Posted by Grrr View Post
    BTW theres no vlax-delete function, you can check in VLIDE:
    Code:
    _$ vlax-delete
    nil
    _$ vla-delete
    #<SUBR @00000083291f4188 vla-Delete>
    So the correct call would be either (vla-delete <vla-object>) or (vlax-invoke-method <vla-object> 'Delete).
    Thanks. So basically what you're saying is it needs an argument in the form of a <vla-object> ?

  9. #9
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,478

    Default

    Quote Originally Posted by 3dwannab View Post
    Thanks. So basically what you're saying is it needs an argument in the form of a <vla-object> ?
    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.

  10. #10
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,249

    Default

    Registered forum members do not see this ad.

    Good catch Grrr,

Similar Threads

  1. vlax-curve-getDistAtPoint, vlax-curve-getParamAtPoint
    By Grrr in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 21st Jul 2016, 05:22 am
  2. vlax-get-property on (vlax-get-acad-object).
    By Qonfire in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 21st May 2012, 05:18 pm
  3. I can't delete lines using the delete button!!
    By lofty in forum AutoCAD General
    Replies: 6
    Last Post: 10th Dec 2009, 07:36 pm
  4. I can't delete line using delete and backspace keys
    By alif in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 21st Apr 2009, 03:42 am
  5. vlax-curve-getStartParam .... vlax-curve-getStartPoint
    By Lee Mac in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 19th Jan 2009, 05:28 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts