TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dommy2Hotty on June 24, 2005, 04:37:01 PM
-
I want to run a vba macro on all layouts. I would like to put it into a pull down menu. Once clicked, the .dvb file gets loaded and the macro is ran. Then the tab is switched, macro is run again. I have the first (easy) part in the menu, but the tab switching is a whole 'nother monster. I tried disecting CAB's Plot Tabs routine, but now my head hurts. Is there a down and dirty tab switch routine that I can mess with?
-
use the thisdrawing.layoutswitched event
-
here is an example
Private Sub AcadDocument_LayoutSwitched(ByVal LayoutName As String)
Dim dblLTScale As Double
Dim dblDimScale As Double
dblLTScale = 0.6 * (Val(ThisDrawing.GetVariable("DIMSCALE")))
If dblLTScale = 0 Then
dblLTScale = 0.6
End If
With ThisDrawing
If .ActiveSpace = acModelSpace Then
.SetVariable "LTSCALE", dblLTScale
ThisDrawing.Regen acAllViewports
Exit Sub
Else
.SetVariable "LTSCALE", 0.6
.SetVariable "PSLTSCALE", 1
ThisDrawing.Regen acAllViewports
Exit Sub
End If
End With
Exit Sub
End Sub
-
Thank you CmdrDuh...I'll see what I can do with that...here's what I was working from (taken from the developer help):
Sub DisplayPlotStyles()
' This example reads and modifies the ShowPlotStyles
' value, and then regenerates all viewports.
Dim ACADLayout As ACADLayout
Dim originalValue As Boolean
' Get the layout object
Set ACADLayout = ThisDrawing.ActiveLayout
' Read and display the original value
' originalValue = ACADLayout.ShowPlotStyles
' MsgBox "The ShowPlotStyles value is set to: " & originalValue
' Modify the ShowPlotStyles preference by changing the value
ACADLayout.ShowPlotStyles = Not ACADLayout.ShowPlotStyles
' MsgBox "The ShowPlotStyles value has been set to: " & ACADLayout.ShowPlotStyles
'Regenerate viewports
ThisDrawing.Regen acAllViewports
I guess this falls into the VBA forum...I thought I would need LISP to do the tab switching...mod should probably move ( if agreed upon )
-
whats really funny was i didn't notice you were asking for a LISP solution. I was just happy to have an answer, I posted before looking to see where it was.
-
so what do you want to do? maybe I can help
-
Well...I'd prefer LISP for now, because I'm coding a entire menu system for a client, and I understand LISP, to some extent.
EDIT: Also because part of the menu is to plot certain tabs. Predefined by menuselection:
[->Plotting...]
[Current View]^C^C^C-PLOT;YES;;HP LaserJet 5000 Series PCL 6.pc3;11x17;INCHES;LANDSCAPE;NO;EXTENTS;1:1;0.290322,-0.000694;YES;MRF11X17.ctb;YES;YES;NO;NO;NO;NO;YES;
[--]
[->All Views for a Single Floor...]
[1st Floor]
[2nd Floor]
[3rd Floor]
[4th Floor]
[<-5th Floor]
[->Single View on ALL Floors...]
[Egress Lighting]
[Exit Signage]
[--]
[Rated Doors]
[Rated Walls]
[--]
[Smoke Resistant Doors]
[Snow and Ice Removal]
[--]
[<-<-Trash and Linen Chutes]
-
I know I'm showing two different things, one VBA for displaying plot styles, and one macro for plotting, but they both deal with tab switching...so...
-
are each tab a view like "egress lighting" or "Rated Doors"?
-
you can code it all in vba if you want, and call it from your menu w/ LISP. thats what I do.
[2nd Floor](command "-vbarun" "Whatever")
just make sure you (vl-vbaload "macro") in your mnl file
-
yes...each tab is a floor and view...for example:
1st Floor - Egress Lighting
2nd Floor - Egress Lighting
1st Floor - Exit Signage
2nd Floor - Exit Signage
etc...
-
Is this for LT?
I have a plot macro you can edit with all your settings and it works better than -plot
-
Public Sub Vendor1117()
Dim Layout As AcadLayout
Set Layout = ThisDrawing.ActiveLayout
Layout.RefreshPlotDeviceInfo
Layout.ConfigName = "11x17Draft.pc3"
Layout.PlotType = acExtents
Layout.PlotRotation = ac90degrees
Layout.StyleSheet = "11X17-CHECKSET.ctb"
Layout.CanonicalMediaName = "ANSI_B_(11.00_x_17.00_Inches)"
Layout.PaperUnits = acInches
Layout.StandardScale = acScaleToFit
Layout.ShowPlotStyles = False
ThisDrawing.Plot.NumberOfCopies = 1
Layout.CenterPlot = True
Layout.RefreshPlotDeviceInfo
ThisDrawing.Regen acAllViewports
ZoomExtents
ThisDrawing.Plot.PlotToDevice
Set Layout = Nothing
'ThisDrawing.Close True ' do yo want to close the dwg?
Exit Sub
End Sub
-
You should be able to see the parts to change for your HP printer. And depending on if ctb files need to change, or printers change, you just either copy paste and edit OR change this to a function and pass arguments to it.
-
Not LT...the company will be upgrading from R14 to 2004. I have full control over this entire system, so as long as I can understand it, I'll use it. If I'm called to add something to the menu, like another view (i.e. fire extinguishers), then I need to be able to make that change and modify anything else it affects with no problem. I'm really just getting into VBA, so I'm not fully comfortable with it yet. But as long as I can understand what's going on with it, I'll use it.
P.S. I appreciate the help :twisted:
-
I love writing menucode so I can help you work any bugs you come across.
-
To me, menucode is more rewarding. I can show that off better than I can any other code I write. Granted, some code does some pretty impressive stuff, but to the non-AutoCAD user, I think menus have the biggest impact.
Which is exactly what this is for. It's a menu that anyone in the company can use with no knowledge of AutoCAD. The client does monthly checks of it's systems throughout the building (mostly fire protection equipment and such), and this is so Joe Schmo can walk up, click on the floor he's doing the check on, and the system he wants to check, click "Change view" and he's ready to print. Then click "Plot current view" and he's got his hardcopy. I'm trying to make this a 3~5 click process for them.
-
You can create menu's and toolbars of any code your write: vba/lisp/etc... They'll never know the difference.
-
Dommy,
Take a look in PLottabs Zoom subroutine. It steps through each tab.
Here it is:
;; ---------------------------------------------------------------------------
;; Function: zoom_layouts
;; Purpose : Zoom Extents For Layout Tabs, Closes any active viewports first
;; Params : lay_lst: list of layout names to zoom [CAB030805]
;; ---------------------------------------------------------------------------
(defun zoom_layouts (lay_lst / lay)
(setq *acad* (vlax-get-acad-object)
*doc* (vla-get-activedocument *acad*)
)
(setq lay_lst (mapcar '(lambda (x) (strcase x)) lay_lst))
(vlax-for lay (vla-get-layouts *doc*) ; step through layouts
(if (member (strcase (vla-get-name lay)) lay_lst)
(progn
(vla-put-activelayout *doc* lay) ; activate layout
(and
(= (vla-get-activespace *doc*) 0) ; If not in paperspace
(= (vla-get-mspace *doc*) :vlax-true) ; in mspace viewport
(vla-put-mspace *doc* :vlax-false) ; de-activate vp
)
;; ======= Start your code here ============
(vla-zoomextents *acad*)
;; ======= End your code here ==============
)
)
)
)
Another way to step through the tabs is this:
(defun c:test (/ tab)
(foreach tab (vl-remove "Model" (layoutlist))
(setvar "ctab" tab) ; set tab current
(if (> (getvar "cvport") 1)
(command ".pspace") ; close viewport
)
(getpoint "\nPress Enter to continue.")
)
(princ)
)
You will notice that the order is the created order of the layouts not the
displayed order.
This one uses the display order.
(defun c:test (/ tab)
;; get the tabs with the order number
(vlax-map-collection
(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
'(lambda (x) (setq tab-list (cons x tab-list))))
;; sort in tab order
(setq tab-list (vl-sort tab-list '(lambda (x y)
(< (vla-get-taborder x) (vla-get-taborder y)))))
;; make list of names into strings remove Model space
(setq tab-list (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
(foreach tab tab-list
(setvar "ctab" tab) ; set tab current
(if (> (getvar "cvport") 1)
(command ".pspace") ; close viewport
)
(getpoint "\nPress Enter to continue.")
)
(princ)
)
Enjoy
-
Fantastic! Thanks CAB...I'll dive in at lunch.