.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PrinterConfigPath with two paths

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
matus.brlit
2462 Views, 11 Replies

PrinterConfigPath with two paths

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

 

11 REPLIES 11
Message 2 of 12

Hmmm..

What version of Autocad and what version of Visual Studio? 

 

Message 3 of 12

AutoCAD 2012, VS Express 2008

Message 4 of 12

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 12

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

 

Message 6 of 12

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

Doesn't like two different paths. Huh? 

 

Who would have thought. 

 

 

Message 7 of 12


@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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 12


@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.

Message 9 of 12

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


 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 10 of 12
Rob.O
in reply to: Alexander.Rivilis

I know this topic is a couple of years old, but I am trying to replicate this in 2015 with no sucess.

 

Has anyone written an update that works in 2015?

 

Strange thing... if I strip out all of the Initialization functionality, and turn it into a class library, I can get it to work through an Visual Studio debug session.  But if I build the solution and startup AutoCAD detached from Visual Studio, it will not run properly after NETLOADing the function.  It runs, but after I open the Options dialog, it hangs for about 2 minutes before it finally opens.  Then, the paths are only displying the latest value entered instead of both values I have added.

 

Anyone know of a reason why it would work through a debug session, but not through a detached session of AutoCAD?

 

TIA!

 

Rob

Message 11 of 12
Alexander.Rivilis
in reply to: Rob.O

Function acedGetEnv in ObjectARX 2015 has new signature:

int            acedGetEnv (const ACHAR *sym, ACHAR  *var, size_t nBufLen);

 instead of ObjectARX 2014 and early:

int            acedGetEnv (const ACHAR *sym, ACHAR  *var);

 So code have to look like this (not tested):

[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedGetEnv")]
extern static private Int32 acedGetEnv15(string var, StringBuilder val, UIntPtr valLen);

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 12 of 12
Rob.O
in reply to: Alexander.Rivilis

Thank you Alexander!

 

I saw that the function changed when I was looking through the 2015 arxdoc.chm for info on it, but I kind of glazed over it!

 

Works perfectly!

 

Keep up the great work!

 

Rob

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost