.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newly created entity doesn't show up in drawing

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
421 Views, 6 Replies

Newly created entity doesn't show up in drawing

I'm working through the examples in the dotnet samples, with vb.net, and I've run accross a problem I can't figure out.
In the sample code "Ents", the program creates a line and circle, and I run it and it works.
However, when I snip out the "CreateLine()" function and use it in another program I'm working on in vb.net, the lline doesn't show up in the drawing. The debugger goes through the function line by line with no problem, it just doesn't draw the line onscreen.
I'm sure it's a newbie issue, but any help would be appreciated.

Thanks,
David

{code}
Public Function CreateLine() As ObjectId
Dim startpt As New Point3d(4.0, 2.0, 0.0)
Dim endpt As New Point3d(10.0, 7.0, 0.0)
Dim pLine As New Line(startpt, endpt)

Dim lineid As ObjectId
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As DBTransMan = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction()
Try
Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
lineid = btr.AppendEntity(pLine)
tm.AddNewlyCreatedDBObject(pLine, True)
ta.Commit()
Finally
ta.Dispose()
End Try
Return lineid
End Function
{code}
6 REPLIES 6
Message 2 of 7
chiefbraincloud
in reply to: Anonymous

First glance, it all looks fine. The only significant difference I see between your code and my similar function is that I don't use the GetObject and AddNewlyCreatedDBObject from the transaction manager object, I use the ones from the transaction itself. So instead of tm.GetObject, tm.AddNewly..., mine is ta.GetObject, ta.AddNewly....

At some level in my mind I would think the way you did it would be ok, because the TM should be Getting and Adding to the Top Level Transaction automatically, but I haven't done it that way.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 7
Anonymous
in reply to: Anonymous

When adding an object, you want to add it to the current active transaction, not the manager (tm) in your case.
Also, have a look into the 'Using' statements.

{code}
Public Function CreateLine() As ObjectId

Dim startpt As New Point3d(4.0, 2.0, 0.0)
Dim endpt As New Point3d(10.0, 7.0, 0.0)
Dim pLine As New Line(startpt, endpt)
Dim lineid As ObjectId
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database

''Change to a Using Statement
Using ta As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = ta.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = ta.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
lineid = btr.AppendEntity(pLine)
''Add the object to the current transaction, not the transaction manager
ta.AddNewlyCreatedDBObject(pLine, True)
''Commit the transaction
ta.Commit()
''Automatically Disposes of the Transaction
End Using

Return lineid
End Function
{code}
Message 4 of 7
Anonymous
in reply to: Anonymous

Is the method you posted the method that works in the Autodesk sample, but
doesn't work in another program you're trying to use it in?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6294035@discussion.autodesk.com...
I'm working through the examples in the dotnet samples, with vb.net, and
I've run accross a problem I can't figure out.
In the sample code "Ents", the program creates a line and circle, and I run
it and it works.
However, when I snip out the "CreateLine()" function and use it in another
program I'm working on in vb.net, the lline doesn't show up in the drawing.
The debugger goes through the function line by line with no problem, it just
doesn't draw the line onscreen.
I'm sure it's a newbie issue, but any help would be appreciated.

Thanks,
David

{code}
Public Function CreateLine() As ObjectId
Dim startpt As New Point3d(4.0, 2.0, 0.0)
Dim endpt As New Point3d(10.0, 7.0, 0.0)
Dim pLine As New Line(startpt, endpt)

Dim lineid As ObjectId
Dim db As Database =
Application.DocumentManager.MdiActiveDocument.Database
Dim tm As DBTransMan = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction()
Try
Dim bt As BlockTable = tm.GetObject(db.BlockTableId,
OpenMode.ForRead, False)
Dim btr As BlockTableRecord =
tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
lineid = btr.AppendEntity(pLine)
tm.AddNewlyCreatedDBObject(pLine, True)
ta.Commit()
Finally
ta.Dispose()
End Try
Return lineid
End Function
{code}
Message 5 of 7
Anonymous
in reply to: Anonymous

Yes, I just copied the function from the sample.
Also, DeathTiger, the revised function you posted doesn't result in drawing a line on my AutoCAD screen, so I'm guessing the problem is something I'm doing elsewhere.
I can run through my code line by line in the debugger, it's just that the line doesn't show up.
Message boxes show up, and the values of the variables look correct in execution, it's just the line (in this case) is apparantly shy about showing itself onscreen.
I was trying to create a reversed polyline, and it wasn't showing up onscreen, so I plugged in the sample function "CreateLine()" just to see if a tried and true function would result in a visible line.
?
If anyone is either interested or kind enough, I've attached the Visual Studio file.
Message 6 of 7
Anonymous
in reply to: Anonymous

Notice that in the method you posted, which works in the Autodesk sample,
the Commit() method on the transaction is called.

In your code which calls that method, another transaction is already active,
but you do not call Commit() on it before you call Dispose(), which aborts
the transaction, along with all inner transactions, regardless of whether
they were committed or not.

So, the method that calls the CreatePline or CreatePolyLine method starts a
transaction, but does not commit it.

Even though the inner transaction in the CreatePolyLine and CreateLine
methods are commited, they are still aborted if any enclosing/outer
transactions are not also commited. So, all of your transactions must be
committed by calling Commit() on them before you call Dispose().

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6294317@discussion.autodesk.com...
Yes, I just copied the function from the sample.
Also, DeathTiger, the revised function you posted doesn't result in drawing
a line on my AutoCAD screen, so I'm guessing the problem is something I'm
doing elsewhere.
I can run through my code line by line in the debugger, it's just that the
line doesn't show up.
Message boxes show up, and the values of the variables look correct in
execution, it's just the line (in this case) is apparantly shy about showing
itself onscreen.
I was trying to create a reversed polyline, and it wasn't showing up
onscreen, so I plugged in the sample function "CreateLine()" just to see if
a tried and true function would result in a visible line.
?
If anyone is either interested or kind enough, I've attached the Visual
Studio file.
Message 7 of 7
Anonymous
in reply to: Anonymous

Thanks, Tony- I have some reading to do!
Now it works, after I changed the calling function to move the call to CreateLine() to past the Dispose()

Regards,
David

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost