• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 220
    Registered: ‎03-11-2008
    Accepted Solution

    PrinterConfigPath with two paths

    434 Views, 8 Replies
    05-10-2012 08:18 AM

    Hi,

    I'm trying to set two locations in PrinterConfigPath, but it crashes with fatal error

     

    Dim pref As AcadPreferences = Autodesk.AutoCAD.ApplicationServices.Application.Preferences
    pref.Files.PrinterConfigPath = "T:\wPlotters;T:\Plotters"

    note 1: one location works fine, but i can't figure out, how to put 2 locations there

    note 2: when i set those paths manually, the property contains exactly that string

     

    Please use plain text.
    Distinguished Contributor
    VB_Autocad_guy
    Posts: 136
    Registered: ‎07-24-2009

    Re: PrinterConfigPath with two paths

    05-15-2012 12:00 PM in reply to: matus.brlit
    Hmmm..

    What version of Autocad and what version of Visual Studio? 

     

    Please use plain text.
    Mentor
    Posts: 220
    Registered: ‎03-11-2008

    Re: PrinterConfigPath with two paths

    05-15-2012 10:20 PM in reply to: VB_Autocad_guy

    AutoCAD 2012, VS Express 2008

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: PrinterConfigPath with two paths

    05-16-2012 12:31 AM in reply to: matus.brlit

    I did not try your's code but the same can be done with help of setting environment "PrinterConfigDir" (ObjectARX functions acedGetEnv/acedSetEnv and lisp functions (getenv) and (setenv).

    How to call acedGetEnv/acedSetEnv from .NET: 

    http://www.theswamp.org/index.php?topic=33594.0

    http://www.theswamp.org/index.php?topic=20237.msg362493#msg362493

    http://www.caduser.ru/forum/index.php?PAGE_NAME=message&FID=49&TID=36668&MID=208004#message208004


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Distinguished Contributor
    VB_Autocad_guy
    Posts: 136
    Registered: ‎07-24-2009

    Re: PrinterConfigPath with two paths

    05-16-2012 03:39 PM in reply to: matus.brlit

    Okay so Here's some sample code I don't have any problem using the Autocad Preferences Object

     

        Public Application As Autodesk.AutoCAD.ApplicationServices.Application 'VB.NET Application Object
     Try
                'Acad Preferences Objects
                Dim acPrefComObj As AcadPreferences = Application.Preferences
    
                'Set Support Paths & Preferences
                With acPrefComObj.Files
                    'Editor.WriteMessage("Entered Loop")
    
                    'Change Value in Autocad Preferences if Variable is NOT empty---------------
                    .CustomIconPath = sCustomIconPath
                    .DriversPath = sDriversPath
                   .PrinterDescPath = sPrinterConfigPath
                   .PrinterConfigPath = sPrinterConfigPath
                   .PrinterStyleSheetPath = sPrinterStyleSheetPath
                    .SupportPath = sSupportPath
                    .TempFilePath = sTempFilePath
                    .TemplateDwgPath = sTemplateDwgPath
                     .ToolPalettePath = sToolPalettePath
                    .AutoSavePath = sAutoSavePath
    
                    '---------------------------------------------------------------------------
                    '---------------------------------------------------------------------------
    
                End With
    
    
                Editor.WriteMessage(vbTab & "<<[Support Paths Set>>" & Environment.NewLine)
    
                '---------------------------------------------------------------------------
                'AUTOSAVE SET
                With acPrefComObj.OpenSave
                    .AutoSaveInterval = 11
                End With
    
                Editor.WriteMessage(vbTab & "<<AutoSave Interval Set>>" & Environment.NewLine)
    
                '---------------------------------------------------------------------------
    
                '---------------------------------------------------------------------------
                'DefaultPlot File Path & Printer
                With acPrefComObj.Output
                    .DefaultPlotToFilePath = _
                    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    
                    .DefaultOutputDevice = DefaultPrinterName()
                End With
    
                Editor.WriteMessage(vbTab & "<<Default Printer Set>>" & Environment.NewLine)
                '---------------------------------------------------------------------------
    
    
                Editor.WriteMessage(vbTab & "<<Support Settings Done>>" & Environment.NewLine)
    
                Editor.WriteMessage(vbTab & "<<----------------------------------------------->>" & Environment.NewLine)
    
            Catch ex As Exception
    
                Editor.WriteMessage("[ERROR:" & ex.Message & vbTab & ex.ErrorStatus.ToString)
    
            End Try

     

    Please use plain text.
    Distinguished Contributor
    VB_Autocad_guy
    Posts: 136
    Registered: ‎07-24-2009

    Re: PrinterConfigPath with two paths

    05-16-2012 03:49 PM in reply to: VB_Autocad_guy

    I tested your code on my machine. Invalid Argurment error. 

    Doesn't like two different paths. Huh? 

     

    Who would have thought. 

     

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: PrinterConfigPath with two paths

    05-16-2012 09:22 PM in reply to: VB_Autocad_guy

    VB_Autocad_guy wrote:

    I tested your code on my machine. Invalid Argurment error. 

    Doesn't like two different paths. Huh? 

     

    Who would have thought. 


    The previous version of AutoCAD was not allowed to have more than one path in PrinterConfigPath. That is why there is a problem with Autocad Preferences Object (IMHO). If so, then the only solution - to use acedSetEnv as I wrote above.


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Mentor
    Posts: 220
    Registered: ‎03-11-2008

    Re: PrinterConfigPath with two paths

    05-16-2012 10:28 PM in reply to: Alexander.Rivilis

    Alexander.Rivilis wrote:

    The previous version of AutoCAD was not allowed to have more than one path in PrinterConfigPath. That is why there is a problem with Autocad Preferences Object (IMHO). If so, then the only solution - to use acedSetEnv as I wrote above.



    OK, I will give it a try. I was waiting for another possible solution, because I don't fully understand that invoke voodoo, so I try to avoid it, if I can.

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: PrinterConfigPath with two paths

    05-17-2012 02:46 AM in reply to: matus.brlit

    Minimum testing with AutoCAD 2013.

    C#:

    using System;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.EditorInput;
    using AcRx = Autodesk.AutoCAD.Runtime;
    using AcEd = Autodesk.AutoCAD.EditorInput;
    using AcDb = Autodesk.AutoCAD.DatabaseServices;
    using AcAp = Autodesk.AutoCAD.ApplicationServices;
    using AcWin = Autodesk.AutoCAD.Windows;
    
    [assembly: CommandClass(typeof(SetEnvInNet.MyCommands))]
    
    namespace SetEnvInNet
    {
    
        public static class Env
        {
            static int Ver = AcAp.Application.Version.Major;
            // AutoCAD 2007...2012
            [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedGetEnv")]
            extern static private Int32 acedGetEnv12(string var, StringBuilder val);
            // AutoCAD 2013...
            [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedGetEnv")]
            extern static private Int32 acedGetEnv13(string var, StringBuilder val);
            static public string GetEnv(string var)
            {
                StringBuilder val = new StringBuilder(16536);
                if (Ver <= 12) acedGetEnv12(var, val); else acedGetEnv13(var, val);
                return val.ToString();
            }
            // AutoCAD 2007...2012
            [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedSetEnv")]
            extern static private Int32 acedSetEnv12(string var, string val);
            // AutoCAD 2013...
            [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedSetEnv")]
            extern static private Int32 acedSetEnv13(string var, string val);
            static public void SetEnv(string var, string val)
            {
                if (Ver <= 12) acedSetEnv12(var, val); else acedSetEnv13(var, val);
            }
    
        }
        public class MyCommands
        {
            static public void AddPath(string var, string path)
            {
                StringBuilder oldpath = new StringBuilder(Env.GetEnv(var));
                oldpath.Append(";"); oldpath.Append(path);
                Env.SetEnv(var, oldpath.ToString());
            }
    
            [CommandMethod("SetPath", CommandFlags.Modal)]
            public void TestAddPath()
            {
                AcWin.OpenFileDialog dlg = new AcWin.OpenFileDialog("Select Directory:", "", "", "", 
                    AcWin.OpenFileDialog.OpenFileDialogFlags.AllowFoldersOnly);
                DialogResult ds = dlg.ShowDialog();
                if (ds == DialogResult.OK)
                {
                    AddPath("PrinterConfigDir",dlg.Filename);
                }
            }
        }
    }
    
    
    

     VB.NET (converted from C# with http://www.developerfusion.com/tools/convert/csharp-to-vb/)

    Imports System.Runtime.InteropServices
    Imports System.Text
    Imports System.Windows.Forms
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.EditorInput
    Imports AcRx = Autodesk.AutoCAD.Runtime
    Imports AcEd = Autodesk.AutoCAD.EditorInput
    Imports AcDb = Autodesk.AutoCAD.DatabaseServices
    Imports AcAp = Autodesk.AutoCAD.ApplicationServices
    Imports AcWin = Autodesk.AutoCAD.Windows
    
    <Assembly: CommandClass(GetType(SetEnvInNet.MyCommands))>
    
    Namespace SetEnvInNet
    
    	Public NotInheritable Class Env
    		Private Sub New()
    		End Sub
    		Shared Ver As Integer = AcAp.Application.Version.Major
    		' AutoCAD 2007...2012
    		<DllImport("acad.exe", CallingConvention := CallingConvention.Cdecl, CharSet := CharSet.Unicode, EntryPoint := "acedGetEnv")> _
    		Private Shared Function acedGetEnv12(var As String, val As StringBuilder) As Int32
    		End Function
    		' AutoCAD 2013...
    		<DllImport("accore.dll", CallingConvention := CallingConvention.Cdecl, CharSet := CharSet.Unicode, EntryPoint := "acedGetEnv")> _
    		Private Shared Function acedGetEnv13(var As String, val As StringBuilder) As Int32
    		End Function
    		Public Shared Function GetEnv(var As String) As String
    			Dim val As New StringBuilder(16536)
    			If Ver <= 12 Then
    				acedGetEnv12(var, val)
    			Else
    				acedGetEnv13(var, val)
    			End If
    			Return val.ToString()
    		End Function
    		' AutoCAD 2007...2012
    		<DllImport("acad.exe", CallingConvention := CallingConvention.Cdecl, CharSet := CharSet.Unicode, EntryPoint := "acedSetEnv")> _
    		Private Shared Function acedSetEnv12(var As String, val As String) As Int32
    		End Function
    		' AutoCAD 2013...
    		<DllImport("accore.dll", CallingConvention := CallingConvention.Cdecl, CharSet := CharSet.Unicode, EntryPoint := "acedSetEnv")> _
    		Private Shared Function acedSetEnv13(var As String, val As String) As Int32
    		End Function
    		Public Shared Sub SetEnv(var As String, val As String)
    			If Ver <= 12 Then
    				acedSetEnv12(var, val)
    			Else
    				acedSetEnv13(var, val)
    			End If
    		End Sub
    
    	End Class
    	Public Class MyCommands
    		Public Shared Sub AddPath(var As String, path As String)
    			Dim oldpath As New StringBuilder(Env.GetEnv(var))
    			oldpath.Append(";")
    			oldpath.Append(path)
    			Env.SetEnv(var, oldpath.ToString())
    		End Sub
    
    		<CommandMethod("SetPath", CommandFlags.Modal)> _
    		Public Sub TestAddPath()
    			Dim dlg As New AcWin.OpenFileDialog("Select Directory:", "", "", "", AcWin.OpenFileDialog.OpenFileDialogFlags.AllowFoldersOnly)
    			Dim ds As DialogResult = dlg.ShowDialog()
    			If ds = DialogResult.OK Then
    				AddPath("PrinterConfigDir", dlg.Filename)
    			End If
    		End Sub
    	End Class
    End Namespace
    
    
    

     


    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.