How would I Reload a linetype... the linetype already exists in the drawing...
But I want to update the linetype defintition.
This doesn't work.
I need to open the linetyperecord... but what do I use to reload or re-define the linetablerecord.
Dim db As Database = ActiveDrawing.Database Dim ed As Editor = editor Const filename As String = "SFR_LINETYPES.lin" Try Dim path As String = HostApplicationServices.Current.FindFile(filename, db, FindFileHint.Default) db.LoadLineTypeFile("*", path)
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
What about setting EXPERT system variable in value >= 3?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Those solutions don't work.
I need to delete the linetype and then reimport or re-define it completely.
For whatever reason It's not working.
Autocad 2011
Windows XP
using art's reference above, viru says that a drawing's line type definitions get updated when its .lin file is loaded (as you show in your post). therefore as long as your drawing continues to use its .lin file, the line type definition in the .lin file has to be changed (presuming the line type name stays the same)
If CommanfFlags is set to Session
you have use LockDocument, i.e.:
[CommandMethod("relaodLinetype", CommandFlags.Session)] public static void relaodLinetype() { // Set full path of .LIN file herer: string linfile = @"C:\Test\SFR_LINETYPES.lin"; DocumentCollection docManager = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager; Database db = docManager.MdiActiveDocument.Database; using (DocumentLock doclock = docManager.MdiActiveDocument.LockDocument()) { Transaction trans = db.TransactionManager.StartTransaction(); bool bReload = false; using (trans) { LinetypeTable table = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead) as LinetypeTable; if (table.Has("CENTER")) bReload = true; } System.Int16 fileDia = (System.Int16) Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("FILEDIA"); Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", 0); //reload using linetype command... Object acadObject = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication; object ActiveDocument = acadObject.GetType().InvokeMember("ActiveDocument", System.Reflection.BindingFlags.GetProperty, null, acadObject, null); object[] dataArry = new object[1]; if (bReload) { dataArry[0] = "-linetype Load CENTER\n" + linfile + "\nYes\n "; } else { dataArry[0] = "-linetype Load CENTER\nacad.lin\n "; } ActiveDocument.GetType().InvokeMember( "SendCommand", System.Reflection.BindingFlags.InvokeMethod, null, ActiveDocument, dataArry); Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", fileDia); } }
~'J'~
Many Thanks Hallex, as you've helped me when I was in a pickle before.
Having some success here!
It works!
Two follow-up Questions:
1.
So why use the
ActiveDocument.[GetType]().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, Nothing, ActiveDocument, dataArry)
instead of
ActiveDrawing.SendStringToExecute("-linetype load....etc",False,False,False)
Why use the InvokeMember? Does it work faster or better? What's the difference.
Could I just use:
Public Shared Sub SendCommand(ByVal Command As String) Dim doc As Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument doc.SendStringToExecute(Command, False, False, True) End Sub
As my function/method for sending commands? What should I dig into to learn more about this?
2. What does LockDocument do exactly, (Yes obviously it locks the document) but why do it on the linetype load?
Oh for anybody following along here's my code;
<CommandMethod("reloadLinetype", CommandFlags.Session)> _ Public Shared Sub Reload_LineType() ' Set full path of .LIN file herer: Dim linfile As String = gstrc_SFR_LineType_FullFileName Dim linName As String = "PNEUMATIC" Dim bReload As Boolean = False '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim DB As Database = acDoc.Database Try 'Lock Document Using DocLock As DocumentLock = acDoc.LockDocument '' Start a transaction Using TR As Transaction = DB.TransactionManager.StartTransaction '' Open the Linetype table for read Dim acLineTbl As LinetypeTable acLineTbl = TR.GetObject(DB.LinetypeTableId, _ OpenMode.ForWrite) If acLineTbl.Has(linName) = true Then bReload = True End If ' Save the changes and dispose of the transaction TR.Commit() End Using End Using Dim fileDia As System.Int16 = CShort(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("FILEDIA")) Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", 0) 'reload using linetype command... Dim acadObject As [Object] = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication Dim ActiveDocument As Object = acadObject.[GetType]().InvokeMember("ActiveDocument", System.Reflection.BindingFlags.GetProperty, Nothing, acadObject, Nothing) Dim dataArry As Object() = New Object(0) {} If bReload Then dataArry(0) = "-linetype Load " & linName & vbLf & linfile & vbLf & "Yes" & vbLf & " " Else dataArry(0) = "-linetype Load " & linName & vbLf & "acad.lin" & vbLf & " " End If ActiveDocument.[GetType]().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, Nothing, ActiveDocument, dataArry) Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FILEDIA", fileDia) dataArry(0) = "regen" & vbLf ActiveDocument.[GetType]().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, Nothing, ActiveDocument, dataArry) Catch Console.WriteLine("Error in LoadLineType") End Try End Sub
In reponse to VB_Autocad_guy...
The InvokeMember() code is calling the COM interop's AcadDocument.SendCommand() method, except it is calling this using the .NET reflection library's late binding technique. You can google this for more details.
The AcadDocument.SendCommand() method has the advantage of being executed straight away (i.e. synchronously) versus the Document.SendStringToExecute() method which is executed after your code has finished (i.e. asynchronously).
Note that for the COM AcadDocument.SendCommand() method to work synchronously it must be called in the application context (i.e. CommandFlags.Session needs to be set).
Calling this method using late binding is significantly slower than if you reference the interop dll directly in your project. However the advantage is that it will work for both 32-bit and 64-bit systems as well as different versions of AutoCAD - i.e. you don't have to create multiple builds just for a simple COM interop call every now and then.
It's a nice trick to know.
For some further background refer to these posts:
http://through-the-interface.typepad.com/through_the_interface/2006/08/techniques_for_.html
Art
Oh and if you are accessing a document from the application context (i.e. CommandFlags.Session) then you need to lock any document before you edit it, hence the DocumentLock.
This example doesn't work with localized AutoCAD. My command enters in an infinite loop and writes messages to command line like "The command "-LINETYPE" doesn't exist".
How to write this line correctly in this situation?
dataArry[0] = "-linetype Load CENTER\n" + linfile + "\nYes\n ";