so... i'm looking to select a block reference, take it's wcs position, translate the coordinates to the current ucs and then create an xline using those translated coordinates. simple, right?
i simplified some code to test that i could properly build an xline in a current ucs. i just threw in static point3d values instead of grabbing them from another object. it worked as expected:
<CommandMethod("test")> _ Public Sub test() 'get the active document, editor and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acDocEd As Editor = acDoc.Editor Dim acCurDb As Database = acDoc.Database 'start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() 'open the table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) 'open the record for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'define the current ucs Dim ucsDesign As Matrix3d = acDocEd.CurrentUserCoordinateSystem 'define the points Dim ptBase As Point3d = New Point3d(0, 0, 0) Dim ptSecond As Point3d = New Point3d(0, 1, 0) 'translate the points Dim ptUcsBase As Point3d = ptBase.TransformBy(ucsDesign) Dim ptUcsSecond As Point3d = ptSecond.TransformBy(ucsDesign) 'write the result to the command line acDocEd.WriteMessage(vbLf & ptUcsBase.ToString() & vbLf & ptUcsSecond.ToString()) 'create the xline Dim acXline As Xline = New Xline() acXline.BasePoint = ptUcsBase acXline.SecondPoint = ptUcsSecond 'add the xline to the drawing acBlkTblRec.AppendEntity(acXline) acTrans.AddNewlyCreatedDBObject(acXline, True) 'commit the changes acTrans.Commit() End Using
End Sub
here, i revised the code so that a block reference's objectid is passed from another procedure, the origin is determined, translated to the current ucs and the points are tailored for the xline's basepoint and secondpoint. i threw in a few writemessages to ensure that the coordinates were indeed what i was looking for and they match up, but for some reason, the xline now fails to create itself.
'define the current ucs Dim ucsDesign As Matrix3d = acDocEd.CurrentUserCoordinateSystem 'start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() 'open the connector block for read Dim acBlock As BlockReference = acTrans.GetObject(idConnector, OpenMode.ForRead) 'save connector origin Dim ptOrigin As Point3d = acBlock.Position 'translate the point to the current ucs Dim ptUcsOrigin As Point3d = ptOrigin.TransformBy(ucsDesign.Inverse) 'show me the block position acDocEd.WriteMessage(vbLf & ptOrigin.ToString()) acDocEd.WriteMessage(vbLf & ptUcsOrigin.ToString()) 'open the table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) 'open the record for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'define the points Dim ptBase As Point3d = ptUcsOrigin Dim ptSecond As Point3d = New Point3d(ptUcsOrigin.X, ptUcsOrigin.Y + 1.0, ptUcsOrigin.Z) 'show me the points acDocEd.WriteMessage(vbLf & ptBase.ToString() & vbLf & ptSecond.ToString()) 'create the xline Dim acXline As Xline = New Xline() acXline.BasePoint = ptBase acXline.SecondPoint = ptSecond 'add the xline to the drawing acBlkTblRec.AppendEntity(acXline) acTrans.AddNewlyCreatedDBObject(acXline, True) 'commit the changes acTrans.Commit() End Using
i'm hoping somebody could point out a simple mistake that i'm making and end this headache. i've rearranged this code multiple times, tried a couple different approaches, scoured the forums and even resorted to the less-than-elegant:
'create the xline Dim cmdString As String = "._xline " & ptUcsOrigin.X & "," & ptUcsOrigin.Y & "," & ptUcsOrigin.Z & " " & ptUcsOrigin.X & "," & ptUcsOrigin.Y + 1.0 & "," & ptUcsOrigin.Z & " " acDoc.SendStringToExecute(cmdString, True, False, False)
but i need to use the xline object after i've created it, so this sendstringtoexecute crap won't work.
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
there is one difference between the code snippets that's probably worth mentioning. the simplified test code that worked didn't include:
Imports Autodesk.Gis.Map
it's used in another class, but in the same module. is it possible that this interferes?
Maybe instead of
acXline.BasePoint = ptBase acXline.SecondPoint = ptSecond
using:
acXline.BasePoint = ptBase.TransformBy(ucsDesign) acXline.SecondPoint = ptSecond.TransformBy(ucsDesign)
?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
thanks for the reply!
i'm guessing the intention would be to remove unnecessary variables?
i've tried rearranging the code to pass the information as direct as possible and it still fails.
'create the xline Dim acXline As Xline = New Xline() acXline.BasePoint = acBlock.Position.TransformBy(ucsDesign.Inverse) acXline.SecondPoint = New Point3d(acBlock.Position.X, acBlock.Position.Y + 1.0, acBlock.Position.Z)
the frustrating thing is, i'm able to see my result at the command line. i know the information is being passed, it's just not being used by either the xline class or the appendentity/addnewlycreateddboject methods.
Class Xline needed coordinates in WCS. So after all calculation you have to translate coordinates from UCS to WCS.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
thank you very much alexander. dealing with wcs coordinates did the trick. i was also missing a very important acTrans.Commit() buried in some nested transactions!!
'start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() 'save connector origin Dim ptBase As Point3d = acBlock.Position 'open the table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) 'open the record for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'define the second point, by translating it into the ucs and modifying Dim ptRef As Point3d = ptBase.TransformBy(ucsDesign.Inverse) Dim ptUcsSecond As Point3d = New Point3d(ptRef.X, ptRef.Y + 1.0, ptRef.Z) 'translate the modified point back into wcs Dim ptSecond As Point3d = ptUcsSecond.TransformBy(ucsDesign) 'show me the points acDocEd.WriteMessage(vbLf & ptBase.ToString() & vbLf & ptSecond.ToString()) 'create the xline Dim acXline As Xline = New Xline() acXline.BasePoint = ptBase acXline.SecondPoint = ptSecond 'add the xline to the drawing acBlkTblRec.AppendEntity(acXline) acTrans.AddNewlyCreatedDBObject(acXline, True) 'commit the changes acTrans.Commit() End Using
Can't find what you're looking for? Ask the community or share your knowledge.