I am new so I hope this is the correct location for this post (it involves LISP but it is written in Visual Studio Vb.NET, it has no .lsp associated). I hope this is a simple answer, but my knowledge of LISP is only what I have read from a dew examples online. I am using Cad11, VS10 with VB.NET.
I have a simple function that breaks down the file name and populates 3 fields with the correct names. In my template they all get changed correctly, but when I make a new .dwg it takes a few (hopefully unnecessary) steps to get them to change. The very 1st time opening Cad, the fields do not get recognized ( !fieldname1 returns a nil). If I close the .dwg and reopen it the fields pull the correct value but do not change in model space (ex -- !fieldname1 returns 12345, but model space is still showing 54321 in the field). In order to get the value to change I have to type the Field command in Cad, I don't have to do anything in it, I can immediately close the Field form and then do a regen to get model space to show the correct values.
My idea was to hard code in the Field command and hope to be able to close that before the user knows it is even open, but I still don't think that will solve the 1st time Cad is opened problem, and I am having no luck with getting that lisp command to run (like it said, very limited experience with it). It could just be the syntax is wrong since it is so simple but here is what I thought would work.
ThisDrawing.SendCommand("field" & vbCr)
I have a thisdrawing...("!fieldname1" & vbcr) that correctly returns the value in the command bar right above this.
In the command bar 'field' shows up but the form does not open. Any suggestions on how to solve this are greatly appreciated!
Thanks for any help, and sorry for the long post but I was trying to give as much info as possible to clarify what I am trying to achieve.
The fieldeval variable should be set to 31 in each drawing.
This value is set per drawing.
Also this may be from the type of object you are storing the field into. Attributes / Mtext.
Mtext may not update.
If you can post an example it would help
drawing and code
Hi arcticad, thank you for the reply.
I went through about 5 of the templates that I have and they all seem to bee 31 when I do a fieldeval.
They are MText, the way I got them is...
1. Typed this routine in cad
(setq "fieldname1" field1)
(setq "fieldname2" field2)
(setq "fieldname3" field3)
2. Typed 'field' to open the menu
3.LispVariable --> fieldname1,2,3 --> upper
4. Placed them in .dwg and matchprop'ed them to the old MText.
My code is very simple...
If ThisDrawing.FullName.Contains("-") then 'break it apart If (Filename.Length = 3) then ThisDrawing.SendCommand("(setq fieldname1""" ...'filler for breaking the filename string into my sections))
ThisDrawing.SendCommand("!fieldname1" & vbcr) 'just a test to see value
ThisDrawing.SendCommand("field" & vbcr) 'does not open the Field Form End If End If
[/code] sorry for the way the code is compiled here, i tried to make it half way understandable
Before type 'field' / 'regen' ...
Is this what you were looking for?
Is my method of placing the fields incorrect?
This will check for any fields in the MTEXT and force AutoCAD to evaluate the MTEXT. It will run when you open a file or type in "UF". You will still need to regen.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application Public Class VbExtApp Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Private DocMan As DocumentCollection 'Initialize sub Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Ini
tialize DocMan = AcApp.DocumentManager Dim cDoc = AcApp.DocumentManager.MdiActiveDocument AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated End Sub Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs) updateField() End Sub ' 'Terminate sub Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Ter minate RemoveHandler DocMan.DocumentActivated, AddressOf callback_documentActivated End Sub Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) ' Update Fields In Mtext If e.Document = Nothing Then Exit Sub Else updateField() End If End Sub <CommandMethod("uf")> _ Public Sub updateField() Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument Dim db As Database = doc.Database Using tr As Transaction = db.TransactionManager.StartTransaction() Using doc.LockDocument Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) For Each btrId As ObjectId In bt Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord) For Each objID As ObjectId In btr Dim objEnt As Entity = DirectCast(tr.GetObject(objID, OpenMode.ForRead), Entity) If TypeOf objEnt Is MText Then Dim objMtext As MText = DirectCast(tr.GetObject(objID, OpenMode.ForRead), MText) If objMtext.HasFields Then Dim fieldID As ObjectId = objMtext.GetField Dim field As Field = DirectCast(tr.GetObject(fieldID, OpenMode.ForWrite), Field) field.Evaluate() Dim cEval As String = field.Value End If End If Next Next End Using tr.Commit() End Using End Sub End Class
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.