russell84 Posted November 24, 2008 Posted November 24, 2008 How do i do the following in vba?? Im having trouble translating the code (setq startPt (vlax-curve-getPointAtDist UpperObj stepLength)) (setq startPt2 (vlax-curve-getPointAtDist UpperObj stepLength2)) (setq endPt (vlax-curve-getClosestPointTo BottomObj startPt)) (setq endPt2 (vlax-curve-getClosestPointTo BottomObj startPt2)) (setq a1 (list (car startpt)(cadr startpt))) (setq b1 (list (car endpt)(cadr endpt))) (setq rad1 (angle a1 b1)) (setq ang (alg-ang UpperObj startPt)) (setq ang2 (alg-ang UpperObj startPt2)) Quote
ASMI Posted November 24, 2008 Posted November 24, 2008 VBA hasn't vlax-curve- functions or some another functions for analyse of curves geometry but VB.NET has. Quote
russell84 Posted November 24, 2008 Author Posted November 24, 2008 Thanks asmi. i've found the vlax.cls and curve.cls files that are floating around the internt. Have you had any experience with these? Whats your opinion on using them?? Quote
ASMI Posted November 24, 2008 Posted November 24, 2008 I have some experience with CurveGeometry Interface in .NET, but I prefer C# not VB. Quote
rocheey Posted November 24, 2008 Posted November 24, 2008 Thanks asmi. i've found the vlax.cls and curve.cls files that are floating around the internt. Have you had any experience with these? Whats your opinion on using them?? Ive used them before, but had problems with crashing when running through loops (getting a bazillion points along a spline, constantly calling the class, instead of being able to send a big pile of data in one shot). My *guess* is, (and i hope Im wrong), is that even VLisp runs asynchronously, like AutoLisp, and I was spooning data from VB faster than it could process it. Quote
russell84 Posted November 24, 2008 Author Posted November 24, 2008 SO rocheey if i was to use these class files what would be the method you would use to get around this error?? What did you end up doing?? Otherwise i think i might go that next step and look into the C# Quote
ASMI Posted November 25, 2008 Posted November 25, 2008 If it is pleasant to you VB to you it is absolutely not necessary to study C #. Philosophy of .NET - universality and full compatibility at use of programming languages. On VB.NET to you it is accessible the same objects, methods and properties as on C# or Mahaged C++, a question only in construction of algorithms. However in .NET you will see Object Model AutoCAD which differs from VBA (COM), much additional methods and properties. Quote
rocheey Posted November 25, 2008 Posted November 25, 2008 Although I dabble in .net, vb6, etc, I use VBA because it's *here*. On all the machines. We are a CAD business, not a development house, and having to take code home to tweak a bug or 'whip up' a utility is unacceptable for me. Having said that, it looks like Im going to have to do *something* before we end up in 64-bit, and my VBA routines die a slow death. Without starting a language war, what would be a natural jump for someone with 20+ years PC/GW/Q/VBDos/VB basic experience? Im flirting with Visual Lisp; it's on the machines, and it seems to support activex ... unless VBA is getting replaced with something robust I can get a jump on .... any takers here? Quote
SEANT Posted November 25, 2008 Posted November 25, 2008 Conceivably, AutoCAD will incorporate Visual Studio Tools for Applications (VSTA) sometime in the near future – replacing VBA. That VSTA offering would likely allow programming via any of the current (and perhaps even those in development i.e., F#) flavors of .NET. Concentrating on one of those now would probably be a sensible move for anyone doing ACAD dev work. I’d be interested to hear what the future holds for Visual Lisp. It may well suffer the same long term fate of VBA as they both access the same COM port. Incidentally, rocheey, I see you are using Mechanical: Have you ever used the extended VBA capabilities offered by the McadAuto, BrepAuto, GeAuto libraries? With regard to the original query of this thread the GeAuto library offers the same functionality of vlax-curve. The BrepAuto would allow the more in depth examination of 3dSolids. Quote
russell84 Posted November 26, 2008 Author Posted November 26, 2008 Guys would someone be so kind as to even show me one line of how to use vlax-curve functions within vb.net?? how do you do for instance obtain a point at distance along a curve in vb.net?? Thanks Quote
rocheey Posted November 26, 2008 Posted November 26, 2008 Guys would someone be so kind as to even show me one line of how to use vlax-curve functions within vb.net?? how do you do for instance obtain a point at distance along a curve in vb.net?? Thanks .net? sorry, cant help you there, Im probably greener than anyone there Quote
SEANT Posted November 27, 2008 Posted November 27, 2008 how do you do for instance obtain a point at distance along a curve in vb.net?? Thanks Here's is an example in VB.NET. I don't have much experience in VB.NET - most of my .Net work has been with C# so far - thus it may not be as clean and concise as it could be. The project should include these imports: Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Public Sub PlinePtAtDist() Dim db As Database = HostApplicationServices.WorkingDatabase Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor db.Pdmode = 66 'just to make the points more visible Dim tr As Transaction = db.TransactionManager.StartTransaction() Try Dim peo As PromptEntityOptions = New PromptEntityOptions(vbCr & "Select a lwpline: ") peo.SetRejectMessage(vbCr & "Please select lightweight polyline only! ") peo.AddAllowedClass(GetType(Polyline), True) Dim per As PromptEntityResult = ed.GetEntity(peo) If per.Status <> PromptStatus.OK Then Exit Sub Dim pl As Polyline = tr.GetObject(per.ObjectId, OpenMode.ForRead) Dim len As Double = pl.Length Dim pdo As PromptDoubleOptions = New PromptDoubleOptions(vbCr & "Enter distance from startpoint: ") pdo.AllowNegative = False pdo.AllowZero = True pdo.DefaultValue = len pdo.AllowArbitraryInput = False Dim pdr As PromptDoubleResult = ed.GetDouble(pdo) If pdr.Status <> PromptStatus.OK Or pdr.Value > len Then Exit Sub Dim pt As Point3d = pl.GetPointAtParameter(pl.GetParameterAtDistance(pdr.Value)) 'crux of the process Dim ptAtDist As DBPoint = New DBPoint(pt) Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) btr.AppendEntity(ptAtDist) tr.AddNewlyCreatedDBObject(ptAtDist, True) tr.Commit() Catch ex As Exception tr.Abort() ed.WriteMessage("Error during execution! " & ex.Message) Finally tr.Dispose() End Try End Sub Quote
SEANT Posted November 27, 2008 Posted November 27, 2008 I suppose I should qualify the previous post by saying I’m still relatively new (6 months) to .Net in any of its guises. Most of my work has been in C#, but that should imply that I’m only slightly further along. I’m confident that the code in the previous post will work, but could probably use additional attention to make it more “bulletproof”. Below is a C# version (I've included more entities). It may make for an interesting comparison. Incidentally, I welcome any comments and/or criticism of the code. The project should include: using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; static public void PlinePtAtDist() { // Obtain Database and Editor Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; db.Pdmode = 66; // to make point more visible PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect a pline or spline entity: "); entOpts.SetRejectMessage("\nPlease select LWPoly, 2DPoly, 3DPoly, or spline only! "); entOpts.AddAllowedClass(typeof(Polyline), true); entOpts.AddAllowedClass(typeof(Polyline2d), true); entOpts.AddAllowedClass(typeof(Polyline3d), true); entOpts.AddAllowedClass(typeof(Spline), true); using (Transaction tr = db.TransactionManager.StartTransaction()) { PromptEntityResult prEntRes = ed.GetEntity(entOpts); if (prEntRes.Status != PromptStatus.OK) return; //terminate if no object selected Curve crv = (Curve)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead); Double len = crv.GetDistanceAtParameter(crv.EndParam); //total length of curve PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter distance from startpoint: "); pdo.AllowNegative = false; pdo.AllowZero = true; pdo.DefaultValue = len; pdo.AllowArbitraryInput = false; PromptDoubleResult pdr = ed.GetDouble(pdo); if (pdr.Status != PromptStatus.OK || pdr.Value > len) return;//value has been entered and less than total Point3d pt = crv.GetPointAtParameter(crv.GetParameterAtDistance(pdr.Value));//crux of routine DBPoint ptAtDist = new DBPoint(pt); try { BlockTableRecord btr = (BlockTableRecord)(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); btr.AppendEntity(ptAtDist); tr.AddNewlyCreatedDBObject(ptAtDist, true); tr.Commit(); } catch (System.InvalidOperationException ex) { tr.Abort(); ed.WriteMessage("\nProblem adding point at distance!"); ed.WriteMessage(ex.Message); } finally { ed.WriteMessage("\nPoint at Distance command terminated."); } } } Quote
russell84 Posted November 27, 2008 Author Posted November 27, 2008 Seant, Thank you kindly. I was also looking at the "Hello World!!!" vb.net example floating around the net. But thank you for that - it has helped alot I just needed to get my head around how to access these functions. I'll still having a look at it and will post back asap. Cheers Quote
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.