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
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
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
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
I tested your code on my machine. Invalid Argurment error.
Doesn't like two different paths. Huh?
Who would have thought.
@Anonymous 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
@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.
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
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
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
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.