russell84 Posted January 13, 2009 Posted January 13, 2009 im having trouble with drawing a xline in vb.net its seems to be saying that there is a issue with how im setting the startpoint for the xline. Would someone please give me an example of how to draw a xline in vb.net?? here is some of what i have [size=2][color=#0000ff]Dim [/color][/size][size=2]PEO1 [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptEntityOptions = [/size][size=2][color=#0000ff]New [/color][/size][size=2]PromptEntityOptions(VBCR & "Select top of batter: ") peo1.SetRejectMessage(" Invalid entity! Select LWPoly, 2DPoly, 3DPoly, Line, Arc or Spline only!") peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline2d),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline3d),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](Line),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](spline),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo1.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](arc),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]PER1 [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptEntityResult = ED.GetEntity(PEO1) [/size][size=2][color=#0000ff]If [/color][/size][size=2]PER1.Status <> PROMPTSTATUS.OK [/size][size=2][color=#0000ff]Then Exit Function [/color][/size][size=2]TopCurve = trans.GetObject(per1.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]PEO2 [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptEntityOptions = [/size][size=2][color=#0000ff]New [/color][/size][size=2]PromptEntityOptions(VBCR & "Select bottom of batter: ") peo2.SetRejectMessage(" Invalid entity! Select LWPoly, 2DPoly, 3DPoly, Line, Arc or Spline only!") peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline2d),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](polyline3d),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](Line),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](spline),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) peo2.AddAllowedClass([/size][size=2][color=#0000ff]GetType[/color][/size][size=2](arc),[/size][size=2][color=#0000ff]True[/color][/size][size=2]) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]PER2 [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptEntityResult = ED.GetEntity(PEO2) [/size][size=2][color=#0000ff]If [/color][/size][size=2]PER2.Status <> PROMPTSTATUS.OK [/size][size=2][color=#0000ff]Then Exit Function [/color][/size][size=2]BottomCurve = trans.GetObject(per2.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead) [/size] [size=2][color=#0000ff]Dim [/color][/size][size=2]PDO [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptDoubleOptions = [/size][size=2][color=#0000ff]new [/color][/size][size=2]PromptDoubleOptions(vbcr & "Specify distance between batter ticks: ") PDO.AllowNegative = [/size][size=2][color=#0000ff]False [/color][/size][size=2]PDO.AllowZero = [/size][size=2][color=#0000ff]False [/color][/size][size=2]PDO.AllowArbitraryInput = [/size][size=2][color=#0000ff]False [/color][/size][size=2]PDO.AllowNone = [/size][size=2][color=#0000ff]False [/color][/size][size=2]PDO.DefaultValue = 5 [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]PDR [/size][size=2][color=#0000ff]As [/color][/size][size=2]PromptDoubleResult = ed.GetDouble(PDO) [/size][size=2][color=#0000ff]If [/color][/size][size=2]PDR.Status <> Promptstatus.OK [/size][size=2][color=#0000ff]Then Exit Function [/color][/size] [size=2][color=#0000ff]Dim [/color][/size][size=2]TopCurveLen [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#6f002f]Long [/color][/size][size=2]= topcurve.GetDistanceAtParameter(topcurve.EndParam)[/size] [color=#008000][/color] [size=2][color=#0000ff]Dim [/color][/size][size=2]DistBetween [/size][size=2][color=#0000ff]as [/color][/size][size=2][color=#6f002f]Integer [/color][/size][size=2]= PDR.Value [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]StepLength1 [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#6f002f]double [/color][/size][size=2]= DistBetween [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]StepLength2 [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#6f002f]double [/color][/size][size=2]= (steplength1 / 2) [/size] [size=2][color=#0000ff]Dim [/color][/size][size=2]StartPt1 [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d = [/size][size=2][color=#0000ff]New [/color][/size][size=2]Point3d() StartPt1 = topCurve.GetPointAtDist(StepLength1) ''msgbox (startpt1.ToString) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]StartPt2 [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d = [/size][size=2][color=#0000ff]New [/color][/size][size=2]Point3d() StartPt2 = topcurve.GetPointAtDist(StepLength2) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]EndPt1 [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d = [/size][size=2][color=#0000ff]New [/color][/size][size=2]Point3D() EndPt1 = bottomcurve.GetClosestPointTo(StartPt1, [/size][size=2][color=#0000ff]True[/color][/size][size=2]) ''msgbox (endpt1.ToString) [/size][size=2][color=#0000ff]Dim [/color][/size][size=2]EndPt2 [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d = BottomCurve.GetClosestPointTo(StartPt2, [/size][size=2][color=#0000ff]true[/color][/size][size=2]) [/size] [size=2][color=#0000ff]Dim [/color][/size][size=2]Xline1 [/size][size=2][color=#0000ff]As [/color][/size][size=2]Xline = [/size][size=2][color=#0000ff]New [/color][/size][size=2]Xline() xline1.StartPoint = startpt1[/size][size=2][color=#008000]'PROBLEM HERE [/color][/size][size=2]xline1.EndPoint = ENDPT1[/size][size=2][color=#008000]'PROBLEM HERE [/color][/size][size=2]Xline1.Visible = [/size][size=2][color=#0000ff]True [/color][/size][size=2]AcadBTR.AppendEntity(xLINE1) Trans.AddNewlyCreatedDBObject(Xline1, [/size][size=2][color=#0000ff]True[/color][/size][size=2]) Trans.Commit() [/size] I'm new to vb.net so please be kind. Any example material or websites would help also Quote
SEANT Posted January 14, 2009 Posted January 14, 2009 Have you tried: xline1.BasePoint = startpt1 xline1.SecondPoint = ENDPT1 Quote
russell84 Posted January 14, 2009 Author Posted January 14, 2009 it says that "Secondpoint - is not a member of AutoDesk.Autocad.DatabaseServices.XLINE" Any Other ideas?? Atleast it skipped the StartPt1 as being a error Getting there Quote
SEANT Posted January 14, 2009 Posted January 14, 2009 it says that "Secondpoint - is not a member of AutoDesk.Autocad.DatabaseServices.XLINE" Any Other ideas?? Atleast it skipped the StartPt1 as being a error Getting there That's odd. It is listed in the Docs, and I can get it to work with some C# code I have available. Quote
russell84 Posted January 14, 2009 Author Posted January 14, 2009 Where did you get that help guide?? Does it come with autocad 2009?? That would be really helpful. Im just learning off the net and trial and error Quote
SEANT Posted January 14, 2009 Posted January 14, 2009 Go to: http://usa.autodesk.com/adsk/servlet/index?id=773204&siteID=123112 and click on the License and Download link. That link asks you to provide some information, but in return allows the download of the ObjectARX SDK. In there you find the help files for .NET, as well as ObjectARX, along with some visual Class Maps and numerous code examples for Managed and UnManaged code. Quote
russell84 Posted January 14, 2009 Author Posted January 14, 2009 Thanks very much for that I think that will help a bit having that help guide. Hey i still didnt work out the xline.secondpoint thing in vb.net. So if you find out would you please let me know - thanks mate Quote
SEANT Posted January 14, 2009 Posted January 14, 2009 Thanks very much for that I think that will help a bit having that help guide. Hey i still didnt work out the xline.secondpoint thing in vb.net. So if you find out would you please let me know - thanks mate I have to agree there. If these imports are included: Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices How does this sample work for you: <CommandMethod("QA")> _ Public Sub Asdkcmd1() Dim db As Database = HostApplicationServices.WorkingDatabase Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Using trans As Transaction = db.TransactionManager.StartTransaction() Dim ppo As PromptPointOptions = New PromptPointOptions("Select Base Point :") Dim ppr As PromptPointResult = ed.GetPoint(ppo) If ppr.Status <> PromptStatus.OK Then Exit Sub Dim base As Point3d = ppr.Value ppo.Message = "Select Second Point :" ppo.BasePoint = base ppo.UseBasePoint = True ppr = ed.GetPoint(ppo) If ppr.Status <> PromptStatus.OK Then Exit Sub Dim second As Point3d = ppr.Value If base <> second Then Dim entXline As Xline = New Xline() entXline.BasePoint = base entXline.SecondPoint = second Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) btr.AppendEntity(entXline) trans.AddNewlyCreatedDBObject(entXline, True) End If trans.Commit() End Using End Sub Quote
russell84 Posted January 14, 2009 Author Posted January 14, 2009 i don't know why its not working - but i can't add a "secondpoint" to the xline. Pic Attached. Im using these Imports [size=2][color=#0000ff]Imports [/color][/size][size=2]System [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]System.Type [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]System.CLSCompliantAttribute [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]System.Reflection [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]System.Runtime.InteropServices [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Microsoft.VisualBasic [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Autodesk.AutoCAD.Runtime [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Autodesk.AutoCAD.Geometry [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Autodesk.AutoCAD.ApplicationServices [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Autodesk.AutoCAD.EditorInput [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]Autodesk.AutoCAD.DatabaseServices [/size][size=2][color=#0000ff]imports [/color][/size][size=2]Autodesk.AutoCAD.GraphicsInterface [/size][size=2][color=#0000ff]Imports [/color][/size][size=2]AcadApp = autodesk.AutoCAD.ApplicationServices.Application [/size] Also my Acad references are; acdbmgd.dll acmdg.dll Any ideas?? Quote
SEANT Posted January 14, 2009 Posted January 14, 2009 That is indeed odd. I suppose it's possible that Civil 3D does something different with the Xline implementation. Do you have a standard AutoCAD setup? Does the routine I posted above throw and error when run? Quote
russell84 Posted January 15, 2009 Author Posted January 15, 2009 Well I do have acad 2007 aswell - i have changed the references to that and am running it through acad2007 - still unfortunately the same error. I will try a few more things and get back to you asap. Thanks for your help so far Quote
russell84 Posted January 15, 2009 Author Posted January 15, 2009 one quick one - how do you insert a block and scale it with vb.net. Say block name is "SWPIT" and insertion point is (0, 0, 0) ?? Quote
SEANT Posted January 15, 2009 Posted January 15, 2009 Look at this thread: http://www.cadtutor.net/forum/showthread.php?t=29882 It has some sample code which deal with block references. The BlockReference.ScaleFactors Property controls scaling. Quote
russell84 Posted January 19, 2009 Author Posted January 19, 2009 thanks for that - i had a look over the weekend - was very useful indeed! Hey how do you access a drawings utility and do this?? Code from VBA [size=2][color=#008000] EndPt1 = ThisDrawing.Utility.PolarPoint(StartPt1, Ang1, Dist1) [/color][/size] How do i do that in VB.net?? Thanks Quote
russell84 Posted January 19, 2009 Author Posted January 19, 2009 actually something like this should work [size=2][color=#0000ff] Public Function [/color][/size][size=2]PolarPoint([/size][size=2][color=#0000ff]ByVal [/color][/size][size=2]basepoint [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d, [/size][size=2][color=#0000ff]ByVal [/color][/size][size=2]angle [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#6f002f]Double[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal [/color][/size][size=2]distance [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#6f002f]Double[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2]Point3d [/size][size=2][color=#0000ff]Return New [/color][/size][size=2]Point3d(basepoint.X + (distance * Math.Cos(angle)), basepoint.Y + (distance * Math.Sin(angle)), basepoint.Z) [/size][size=2][color=#0000ff]End Function [/color][/size] 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.