Message 1 of 1
Executing some fuction based on Autocad events such as open new etc...

Not applicable
10-16-2007
05:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
This is a bit longer mail, sorry for that.
I have an issue.with plotting. We are making dwf by printing to "DWF6 ePlot.pc3" and it works fine. All this procedure is fully transparent to the Autocad designer. Our designer usually uses option while plotting to get the setting and save time. Now my issue is that after printing to the DWF printer, the "previous plot" option will show the settings that i coded in VBA.
To solve it, I had used events handlers. First I created the following class.
-----------------------------------------
Public WithEvents objApp As AcadApplication
Public WithEvents objDoc As AcadDocument
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long
'-------------------------------------------------------------
Public Function DefaultPrinter() As String
Dim strReturn As String
Dim intReturn As Integer
strReturn = Space(255)
'This gets the default printer name
intReturn = GetProfileString("Windows", ByVal "device", "", _
strReturn, Len(strReturn))
If intReturn Then
strReturn = UCase(Left(strReturn, InStr(strReturn, ",") - 1))
End If
DefaultPrinter = strReturn
End Function
Private Sub objApp_EndOpen(ByVal FileName As String)
plotcorrector
End Sub
Public Sub plotcorrector()
Dim myconf As AcadPlotConfiguration
On Error Resume Next
Set myconf = ThisDrawing.PlotConfigurations.item("BPC PLOT Window")
If Err Then
Err.Clear
Else
myconf.Delete
End If
Set myconf = ThisDrawing.PlotConfigurations.Add("mPlot", False)
' myconf.Name = DefaultPrinter
myconf.Name = "BPC PLOT Window"
myconf.ConfigName = DefaultPrinter
'myconf.ConfigName = "\\bpcent\X-WC7245 - BW - PS"
Dim mx(0 To 1) As Double
Dim my(0 To 1) As Double
mx(0) = 0
mx(1) = 0
my(0) = 1
my(1) = 1
myconf.SetWindowToPlot mx, my
myconf.PlotType = acWindow
myconf.StyleSheet = "tilt.ctb"
myconf.PaperUnits = acMillimeters
'myconf.RefreshPlotDeviceInfo
myconf.CanonicalMediaName = "A3"
myconf.CenterPlot = True
myconf.UseStandardScale = True
myconf.StandardScale = acScaleToFit
myconf.PlotWithPlotStyles = True
myconf.PlotRotation = ac90degrees
myconf.RefreshPlotDeviceInfo
ThisDrawing.Application.Update
plotcorrector2
End Sub
Public Sub plotcorrector2()
Dim myconf As AcadPlotConfiguration
On Error Resume Next
Set myconf = ThisDrawing.PlotConfigurations.item("BPC PLOT Extents")
If Err Then
Err.Clear
Else
myconf.Delete
End If
Set myconf = ThisDrawing.PlotConfigurations.Add("EPlot", False)
myconf.Name = "BPC PLOT Extents"
myconf.RefreshPlotDeviceInfo
myconf.ConfigName = DefaultPrinter
'myconf.ConfigName = "\\bpcent\X-WC7245 - BW - PS"
Dim mx(0 To 1) As Double
Dim my(0 To 1) As Double
mx(0) = 0
mx(1) = 0
my(0) = 1
my(1) = 1
myconf.SetWindowToPlot mx, my
myconf.PlotType = acExtents
myconf.StyleSheet = "tilt.ctb"
'myconf.RefreshPlotDeviceInfo
myconf.CanonicalMediaName = "A3"
myconf.CenterPlot = True
myconf.PaperUnits = acMillimeters
myconf.SetCustomScale 1, 1
'myconf.UseStandardScale = True
'myconf.StandardScale = ac1_1
myconf.PlotWithPlotStyles = True
myconf.PlotRotation = ac90degrees
myconf.RefreshPlotDeviceInfo
ThisDrawing.Application.Update
End Sub
Private Sub objApp_NewDrawing()
Set objDoc = Documents(Documents.count - 1)
End Sub
Private Sub objDoc_Activate()
plotcorrector
End Sub
---------------------------------------------------------------------------
Then I defined the following macro
------------------------------------------------------------------
Option Explicit
Public objApp As New EventLoader
'Called from lisp for generating the plot option
Public Sub InitializeEvents()
Set objApp.objApp = ThisDrawing.Application
objApp.plotcorrector
End Sub
-----------------------------------------------------------------------
Then I used the following lisp code to call the macro while auto cad is started.
acad.lsp
-----------------------------------------------------------------------
(defun-q Startup ()
(command "-vbarun" "Start")
(command "setvar" "ACADLSPASDOC" 0)
(setq sf "//Server/AD.dvb")
(command "_VBALOAD" sf)
(princ)
(setq sf "loadmenu.CreateAllMenu")
(command "-vbarun" sf)
(princ)
(setq sf "loadmenu.InitializeEvents")
(command "-vbarun" sf)
(princ)
)
(setq S::STARTUP (append S::STARTUP Startup))
---------------------------------------------------------------------
Now my issue is that, the extra plot options not created always.
Sometime it get created and some time not. Even if it get created
the printer is showing as "NONE"
Please advice,
Regards,
Shijith Message was edited by: shijith
This is a bit longer mail, sorry for that.
I have an issue.with plotting. We are making dwf by printing to "DWF6 ePlot.pc3" and it works fine. All this procedure is fully transparent to the Autocad designer. Our designer usually uses
To solve it, I had used events handlers. First I created the following class.
-----------------------------------------
Public WithEvents objApp As AcadApplication
Public WithEvents objDoc As AcadDocument
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long
'-------------------------------------------------------------
Public Function DefaultPrinter() As String
Dim strReturn As String
Dim intReturn As Integer
strReturn = Space(255)
'This gets the default printer name
intReturn = GetProfileString("Windows", ByVal "device", "", _
strReturn, Len(strReturn))
If intReturn Then
strReturn = UCase(Left(strReturn, InStr(strReturn, ",") - 1))
End If
DefaultPrinter = strReturn
End Function
Private Sub objApp_EndOpen(ByVal FileName As String)
plotcorrector
End Sub
Public Sub plotcorrector()
Dim myconf As AcadPlotConfiguration
On Error Resume Next
Set myconf = ThisDrawing.PlotConfigurations.item("BPC PLOT Window")
If Err Then
Err.Clear
Else
myconf.Delete
End If
Set myconf = ThisDrawing.PlotConfigurations.Add("mPlot", False)
' myconf.Name = DefaultPrinter
myconf.Name = "BPC PLOT Window"
myconf.ConfigName = DefaultPrinter
'myconf.ConfigName = "\\bpcent\X-WC7245 - BW - PS"
Dim mx(0 To 1) As Double
Dim my(0 To 1) As Double
mx(0) = 0
mx(1) = 0
my(0) = 1
my(1) = 1
myconf.SetWindowToPlot mx, my
myconf.PlotType = acWindow
myconf.StyleSheet = "tilt.ctb"
myconf.PaperUnits = acMillimeters
'myconf.RefreshPlotDeviceInfo
myconf.CanonicalMediaName = "A3"
myconf.CenterPlot = True
myconf.UseStandardScale = True
myconf.StandardScale = acScaleToFit
myconf.PlotWithPlotStyles = True
myconf.PlotRotation = ac90degrees
myconf.RefreshPlotDeviceInfo
ThisDrawing.Application.Update
plotcorrector2
End Sub
Public Sub plotcorrector2()
Dim myconf As AcadPlotConfiguration
On Error Resume Next
Set myconf = ThisDrawing.PlotConfigurations.item("BPC PLOT Extents")
If Err Then
Err.Clear
Else
myconf.Delete
End If
Set myconf = ThisDrawing.PlotConfigurations.Add("EPlot", False)
myconf.Name = "BPC PLOT Extents"
myconf.RefreshPlotDeviceInfo
myconf.ConfigName = DefaultPrinter
'myconf.ConfigName = "\\bpcent\X-WC7245 - BW - PS"
Dim mx(0 To 1) As Double
Dim my(0 To 1) As Double
mx(0) = 0
mx(1) = 0
my(0) = 1
my(1) = 1
myconf.SetWindowToPlot mx, my
myconf.PlotType = acExtents
myconf.StyleSheet = "tilt.ctb"
'myconf.RefreshPlotDeviceInfo
myconf.CanonicalMediaName = "A3"
myconf.CenterPlot = True
myconf.PaperUnits = acMillimeters
myconf.SetCustomScale 1, 1
'myconf.UseStandardScale = True
'myconf.StandardScale = ac1_1
myconf.PlotWithPlotStyles = True
myconf.PlotRotation = ac90degrees
myconf.RefreshPlotDeviceInfo
ThisDrawing.Application.Update
End Sub
Private Sub objApp_NewDrawing()
Set objDoc = Documents(Documents.count - 1)
End Sub
Private Sub objDoc_Activate()
plotcorrector
End Sub
---------------------------------------------------------------------------
Then I defined the following macro
------------------------------------------------------------------
Option Explicit
Public objApp As New EventLoader
'Called from lisp for generating the plot option
Public Sub InitializeEvents()
Set objApp.objApp = ThisDrawing.Application
objApp.plotcorrector
End Sub
-----------------------------------------------------------------------
Then I used the following lisp code to call the macro while auto cad is started.
acad.lsp
-----------------------------------------------------------------------
(defun-q Startup ()
(command "-vbarun" "Start")
(command "setvar" "ACADLSPASDOC" 0)
(setq sf "//Server/AD.dvb")
(command "_VBALOAD" sf)
(princ)
(setq sf "loadmenu.CreateAllMenu")
(command "-vbarun" sf)
(princ)
(setq sf "loadmenu.InitializeEvents")
(command "-vbarun" sf)
(princ)
)
(setq S::STARTUP (append S::STARTUP Startup))
---------------------------------------------------------------------
Now my issue is that, the extra plot options not created always.
Sometime it get created and some time not. Even if it get created
the printer is showing as "NONE"
Please advice,
Regards,
Shijith Message was edited by: shijith