Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete Page Setups with a Lisp but no VBA?

22 REPLIES 22
Reply
Message 1 of 23
Snowman427
1055 Views, 22 Replies

Delete Page Setups with a Lisp but no VBA?

Given Autodesk no longer supports VBA 6 or earlier and we are still using AutoCAD 2013 it means all the lisp programs that had VBA in them are now useless.

 

So is ther a way to delete all of the page setups in a tab without using VBA in the lisp?

 

Thanks

22 REPLIES 22
Message 2 of 23
Jason.Piercey
in reply to: Snowman427

(deletepagesetup (vla-get-activedocument (vlax-get-acad-object)) "*")

; deletes a pagesetup(s) from a document
; [document] - vla-object, document object
; [name]     - string, name to delete - wildcards allowed
; return: t or nil
; revised 09/03/2003 to handle wildcards correctly
(defun deletePagesetup (document name)
 (if
  (vl-catch-all-error-p
   (vl-catch-all-apply
    (function
     (lambda ()
      (setq name (strcase name))
      (vlax-for x (vla-get-plotconfigurations document)
       (if (wcmatch (strcase (vla-get-name x)) name)
        (vla-delete x) )
       )
      )
     )
    )
   )
  nil
  t
  )
 )

 

Message 3 of 23
Snowman427
in reply to: Jason.Piercey

Yep exactly... That’s the kind of coding doesn’t work anymore.

 

Because Autodesk no longer supports the version of visual basic they have in AutoCAD 2013 you can't run that kind of code. I'm sure there are several other examples this out there.

 

 

Message 4 of 23
Jason.Piercey
in reply to: Snowman427

Have you invoked (vl-load-com)?  Just tested this in 2015, works fine here.

Message 5 of 23
Snowman427
in reply to: Jason.Piercey

I only have AutoCAD 2013. It was recently installed.

 

According to the Autodesk website

usa.autodesk.com/adsk/servlet/index?siteID=123112&id=770215

 

"As of January 31, 2014, Autodesk is no longer authorized to distribute VBA 6 or earlier versions of VBA for use with Autodesk AutoCAD and other Autodesk products"

 

There is no download for AutoCAD 2013 for the application module on their website.

knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/download-the-microsoft-visua...

 

Now I have to covert all the Lisp I have to function without VBA.

 

 

So back to the orginal question is there a way to delete all the page setups in a tab without using VBA?

 

Message 6 of 23
Jason.Piercey
in reply to: Snowman427

If you insist on doing it without activex, they are stored in the "ACAD_PLOTSETTINGS" dictionary.

Message 7 of 23
cad-pe
in reply to: Snowman427

In AutoCAD 2014 hold the Cntrl key down and select the tabs to be deleted, then use the Delete key. If you have a sequence tabs to select, hold the Cntrl key down on the first tab then at the end tab, hold the Cntrol+Shift key and the sequence with be selected, then use the Delete key.

 

Attached is a Layout select LISP file with DCL file routine that can most likely be reworked to delete layout tabs.

Message 8 of 23
Snowman427
in reply to: cad-pe

On all 1400 drawings?

It's the reason I need to get a Lisp to do that.

Message 9 of 23
cad-pe
in reply to: Snowman427

I found this routine using a Google search and it works.

 


 (defun c:deleteallbutcurrentlayout (/)
 (vl-load-com)
 (vlax-map-collection
 (vla-get-layouts
 (vla-get-activedocument (vlax-get-acad-object))
 )
 '(lambda (lay)
 (if (/= (vla-get-name lay) (getvar 'ctab))
 (vl-catch-all-apply 'vla-delete (list lay))
 )
 )
 )
 )
 (c:deleteallbutcurrentlayout)

Message 10 of 23
Snowman427
in reply to: cad-pe

Nice, That's exaclty the VBA script I had in the Lisp I used before it didn't work any more.

Good to see it was still out there, but can't using any of it any more.

Message 11 of 23
cad-pe
in reply to: Snowman427

I'm a little confused about your post. VBA is Visual Basic for Application and is activeX driven and has very differenct syntax that all the LISP code. The code I posted is Visual LISP and differs from the legacy LISP or AutoLISP.

 

The code I posted is Visual LISP and is not VBA.

 

The code I posted to delete tabs works in both AutoCAD 2014 and 2015. I had to use Appload to get it to run in 2015.

Message 12 of 23
dgorsman
in reply to: cad-pe

VBA is the language.  In order to run VBA ie. DVB, you need to install the appropriate VBA enabler.  Visual LISP uses the ActiveX/COM interface which is still present in AutoCAD.  About the only two problems I can think of is missing the (vl-load-com) call and adjusting the security settings for loading.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 13 of 23
Snowman427
in reply to: dgorsman

Yep that's the problem

 

Command: DELETEALLBUTCURRENTLAYOUT
#<VLA-OBJECT IAcadLayouts 0000000046b0fea8>
Command:

 

They changed to Windows 7 loaded AutoCAD 2013 becuase thats what they had and changed all the names of the printers.

So I can load up the new Pagesetups on the 1400+ drawings through a Lisp in the archive set, but can not delete the old Pagesetups with the old printer names.

 

Minor inconveance but would have worked if I could get the VBA code to run. I have several Lisps with this code embeded so this problem is bound to come up several more times.

Message 14 of 23
Jason.Piercey
in reply to: cad-pe

 


@cad-pe wrote:

I found this routine using a Google search and it works.

 



That appears to befor deleting layouts, not pagesetups.  Very different things.

Message 15 of 23
cad-pe
in reply to: Jason.Piercey

This one works nicely. Again, I found it using a Google search.

 

; DELPGSETUPS.LSP - Deletes page setups.


(defun C:DelPgSetups ( / appAcad colPgSetups docCurrent objPgSetup)

    (vl-load-com)

 

    ;get the ACAD application object

    (setq appAcad (vlax-get-acad-object))

 

    ;get the current drawing

    (setq docCurrent (vla-get-ActiveDocument appAcad))

 

    ;get the ACAD_PLOTSETTINGS dictionary

    (setq colPgSetups (vla-get-PlotConfigurations docCurrent))

 

    ; ask for confirmation before deleting

    (initget 1 "Y YES N NO")

    (setq answer

        (substr

            (getkword

                "\nThis will erase all the named page setups ?

                Do you want to continue ? [Yes/No]: "

            )

            1 1

        )

    )

 

    ; if ok, continue to delete all the named page setups

    (if (= answer "Y")

        (progn

            ;;get each page setup in the

            ;ACAD_PLOTSETTINGS dictionary

            (vlax-for objPgSetup colPgSetups

                (princ

                    (strcat "\nDeleting " (vla-get-name objPgSetup))

                )

 

                ;delete the page setup from the dictionary

                (vla-delete objPgSetup)

 

                ;release the page setup

                (vlax-release-object objPgSetup)

            );vlax-for

            (princ "\n\nDone.")

        )

    )

 

    ;;release objects from memory

    (vlax-release-object colPgSetups)

    (vlax-release-object docCurrent)

    (vlax-release-object appAcad)

 

    (princ)

);End of defun DelPgSetups

Message 16 of 23
dgorsman
in reply to: Snowman427

Try looking into TrueView.  One of the coversion options is to remove all page set-ups.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 17 of 23
Jason.Piercey
in reply to: cad-pe


@cad-pe wrote:

This one works nicely. Again, I found it using a Google search.

 

; DELPGSETUPS.LSP - Deletes page setups.


(defun C:DelPgSetups ( / appAcad colPgSetups docCurrent objPgSetup)

    (vl-load-com) 

 


 

That does the same things as I posted, with the addition of added prompts (ie: unwanted interference in a batch situation) but regardless, it's apparently unacceptble for the OP since activex is forbidden for some reason.

Message 18 of 23
cad-pe
in reply to: Snowman427

Sounds like something else is going on with your AutoCAD. Have you tried the code on another AutoCAD machine? I might be missing something in the outcome you want with the code. I believe I understand you want a LISP routine to go through the layout tabs and delete the page setups that name the plotting devices. Am I right? If not let me know.

Message 19 of 23
dmfrazier
in reply to: dgorsman

Hi dgorsman,

I would appreciate it if you could help clarify for me what is actually going on in this thread.  It sounds like the OP is saying that without the VBA enabler installed, VL functions in LISP programs will not work.  Is that true?  Do VL functions need the VBA enabler?

Message 20 of 23
greg_battin
in reply to: Snowman427

;;  Function to delete all user page set ups
;; Posted by; CAB @ http://forums.augi.com/showthread.php?63099-page-setup-import-vlisp
(defun c:Del_Pagesetups (/ curdwg pslayout x) 
  (vl-load-com) 
  (setq 
    curdwg   (vla-get-ActiveDocument (vlax-get-Acad-Object)) 
    pslayout (vla-get-Layout (vla-get-PaperSpace curdwg)) 
  ) ;_ end of setq 
  ;; Call RefreshPlotDeviceInfo before GetPlotDeviceNames 
  (vla-RefreshPlotDeviceInfo pslayout) 
  (vlax-for x (vla-get-Plotconfigurations curdwg) 
    (vla-delete x) 
  ) ;_ end of vlax-for 
)               ; End Plot_config_list 

 

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

Post to forums  

Autodesk Design & Make Report

”Boost