Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete a Named View

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
scot-65
843 Views, 3 Replies

Delete a Named View

How do I delete a named view without closing, then reopening a custom DCL dialog box?

 

This is the command equivalent: (command "-VIEW" "Delete" "View01").

 

I can supply the view name and will send to a subroutine as shown below.

 

Remove one at a time:

(EVC_Remove "View01")

 

and

 

Remove all of them:

(EVC_Remove "*")


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: scot-65

Something as simple as this [minimally tested]:

 

(defun EVC_Remove (viewname)

  (command "_.view" "_delete" viewname)

  (princ)

)

 

Add something like this [untested] if you like:
  (prompt

    (strcat

      "\n"

      (if (= viewname "*") "All named Views" (strcat "View " viewname))

      " deleted."

    ); strcat

  ); prompt

Kent Cooper, AIA
Message 3 of 4
Lee_Mac
in reply to: scot-65

@KenT: As far as I'm aware, you cannot evaluate an AutoCAD command whilst a modal dialog is active, as the user has indicated:


@scot-65 wrote:

How do I delete a named view without closing, then reopening a custom DCL dialog box?


 

The following is untested, but may be suitable:

 

(defun evc_remove ( view / lst )
    (vlax-for v (vla-get-views (vla-get-activedocument (vlax-get-acad-object)))
        (if (wcmatch (strcase (vla-get-name v)) view)
            (setq lst (cons v lst))
        )
    )
    (and lst
        (not
            (apply 'or
                (mapcar
                   '(lambda ( x )
                        (vl-catch-all-error-p
                            (vl-catch-all-apply 'vla-delete (list x))
                        )
                    )
                    lst
                )
            )
        )
    )
)

 

Call the function with a case-insensitive view name, or wildcard pattern, e.g.:

 

(evc_remove "myview")
(evc_remove "*")

 

The function will then return T if all matching views are successfully deleted, else nil if one or more views could not be deleted for whatever reason, or if no matching views are found.

 

Lee

Message 4 of 4
scot-65
in reply to: Lee_Mac

Thanks, I'll give it a try.
I knew it had something to do with "catch-all" and "vla-delete", but I am not that proficient with VL.
I populate the list_box using (tblnext "VIEW"... so there is no problem with text case. After this action you provided I will call again the tblnext to repopulate... In no way the user will ever type the view name.
And Yes, no commands allowed while the DCL is open.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost