Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
scot-65
Posts: 2,083
Registered: ‎12-11-2003
Message 1 of 4 (120 Views)
Accepted Solution

Delete a Named View

120 Views, 3 Replies
01-14-2014 12:32 PM

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
Dyslexia is a permanent physical disability that cannot be seen.
*Expert Elite*
Kent1Cooper
Posts: 4,967
Registered: ‎09-13-2004
Message 2 of 4 (110 Views)

Re: Delete a Named View

01-14-2014 12:57 PM 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
*Expert Elite*
Lee_Mac
Posts: 1,045
Registered: ‎12-29-2009
Message 3 of 4 (97 Views)

Re: Delete a Named View

01-14-2014 02:51 PM 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

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
*Expert Elite*
scot-65
Posts: 2,083
Registered: ‎12-11-2003
Message 4 of 4 (87 Views)

Re: Delete a Named View

01-14-2014 03:36 PM 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
Dyslexia is a permanent physical disability that cannot be seen.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community