Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

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

Delete a Named View

160 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.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
Kent1Cooper
Posts: 5,370
Registered: ‎09-13-2004
Message 2 of 4 (150 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,147
Registered: ‎12-29-2009
Message 3 of 4 (137 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,156
Registered: ‎12-11-2003
Message 4 of 4 (127 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.
Introverts is proof that there is indeed intelligent life on this planet.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.