irneb Posted June 29, 2011 Share Posted June 29, 2011 Anyone have a sample of how to do this? I've tried passing the handle string through the result buffer, then use the Database object's GetObjectId method, though that doesn't work. Basically, I'm trying to get hold of the actual graphical object from a lisp call. Then get that object's ContextManager. Search for an attached context and pass the items in that collection back to lisp as a list. Quote Link to comment Share on other sites More sharing options...
fixo Posted June 30, 2011 Share Posted June 30, 2011 Borrowed from Kean Walmsley Public Shared Function GetIdFromString(ByVal strHandle As String, ByVal db As Database) As ObjectId Dim id As ObjectId = ObjectId.Null Dim lg As Long = System.Convert.ToInt64(strHandle.ToString, 16) Dim hd As Handle = New Handle(lg) ''get then the ObjectId from the Handle id = db.GetObjectId(False, hd, -1) Return id End Function Quote Link to comment Share on other sites More sharing options...
irneb Posted June 30, 2011 Author Share Posted June 30, 2011 Thanks, that turned me onto the "correct" track. Though I've still got a problem: Now I want the DBObject from that Id. If I simply then use id.GetObject(OpenMode.ForRead) I get a fatal error in Vanilla2008. The object I tested was a line I just drew on Layer "0", so it's not erased and not on a locked layer. BTW, I've noticed if I simply send the ename from Lisp, this is already converted to an ObjectId. So I went with that way of doing this, but still get the exact same fatal error. Quote Link to comment Share on other sites More sharing options...
fixo Posted June 30, 2011 Share Posted June 30, 2011 Irne`, I've got often a similar error when I used id.GetObject(OpenMode... Rewriting this part with using trans.GetObject(id,OpenMode... was preventing this error in my codes, now I don't use id.GetObject at all Can you see PM? Quote Link to comment Share on other sites More sharing options...
irneb Posted June 30, 2011 Author Share Posted June 30, 2011 Sure! That works! Here's my code so far: using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; [assembly: CommandClass(typeof(AnnoScalesExt.LispExtendedFunctions))] namespace AnnoScalesExt { /// <summary> /// Class creating functions callable from Lisp to extend its capabilities on working with /// annotative scales. /// </summary> public class LispExtendedFunctions { /// <summary> /// Obtains a list of scales in the current drawing. /// </summary> /// <param name="args">The lisp arguments (if any). Ignored.</param> /// <returns>Returns a result set to lisp as a list containing data regarding each /// scale: ScaleName PaperUnits ModelUnits</returns> [LispFunction("AnnoScalesExt_GetScaleList")] public ResultBuffer GetScaleList(ResultBuffer args) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; ResultBuffer res = new ResultBuffer(); ObjectContextManager ocm = db.ObjectContextManager; if (ocm != null) { ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES"); if (occ != null) { res.Add(new TypedValue((int)LispDataType.ListBegin)); foreach (ObjectContext oc in occ) { if (oc is AnnotationScale) { AnnotationScale asc = (AnnotationScale)oc; res.Add(new TypedValue((int)LispDataType.ListBegin)); res.Add(new TypedValue((int)LispDataType.Text, asc.Name)); res.Add(new TypedValue((int)LispDataType.Double, asc.PaperUnits)); res.Add(new TypedValue((int)LispDataType.Double, asc.DrawingUnits)); res.Add(new TypedValue((int)LispDataType.ListEnd)); } } res.Add(new TypedValue((int)LispDataType.ListEnd)); } else { res.Add(new TypedValue((int)LispDataType.Nil)); } } else { res.Add(new TypedValue((int)LispDataType.Nil)); } return res; } /// <summary> /// Get attached scales of a selected entity. /// </summary> /// <param name="args">The lisp arguments (if any). This should contain either /// the ename or text handle of the object.</param> /// <returns>A list of scale names attached to the object.</returns> [LispFunction("AnnoScalesExt_GetAttachedScaleList")] public ResultBuffer GetAttachedScaleList(ResultBuffer args) { ResultBuffer res = new ResultBuffer(); if ((args != null) && (args.AsArray().Length > 0)) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Array argArray = args.AsArray(); TypedValue tv = (TypedValue)argArray.GetValue(0); ObjectId id = ObjectId.Null; Transaction tr = doc.Database.TransactionManager.StartTransaction(); DBObject obj; using (tr) { if (tv.TypeCode == (int)LispDataType.ObjectId) //ename { id = (ObjectId)tv.Value; } else if (tv.TypeCode == (int)LispDataType.Text) //string, handle { long lg = System.Convert.ToInt64(tv.Value.ToString(), 16); Handle hd = new Handle(lg); id = db.GetObjectId(false, hd, -1); } obj = tr.GetObject(id, OpenMode.ForRead); } if (obj != null) { res.Add(new TypedValue((int)LispDataType.ListBegin)); res.Add(new TypedValue((int)LispDataType.ListEnd)); } { res.Add(new TypedValue((int)LispDataType.Nil, null)); } } else { res.Add(new TypedValue((int)LispDataType.Nil)); } return res; } } } Now I just need to drill into how to get hold of the attached scales ... but that's a different story! BTW, I see you're using VB.Net. If you want to convert my C# code above, I usually use this: http://www.developerfusion.com/tools/convert/csharp-to-vb/ Quote Link to comment Share on other sites More sharing options...
fixo Posted June 30, 2011 Share Posted June 30, 2011 Thanks, I use both of them Many regards Ya da man, Irne` Quote Link to comment Share on other sites More sharing options...
irneb Posted June 30, 2011 Author Share Posted June 30, 2011 Thanks for the help! I've been googling for this a few hours already, then finally thought OK go ask on the forum! Without you pointing me to that code, it would probably still not have worked! Quote Link to comment Share on other sites More sharing options...
fixo Posted June 30, 2011 Share Posted June 30, 2011 Glad if so Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.