- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a program where I am inserting blocks at specific points in model space. I have successfully been able to create a subroutine that will accept a block name, a point3D Location and a layer name and and insert the specified block at the specified location on the specified layer. What I need to do now is to cycle through model space and find all of the pipe objects in model space. I then find the endpoint of each pipe and insert a block at that location. The problem that I am having is that the program crashes when I try to find the objectid of modelspace. I am using the technique discussed in this thread by Jeffrey_H.
Below is the code that I am trying to get to work.
'Test Command to insert the some blocks into the drawing
<CommandMethod("TrimbleTestBlocks")> _
Public Sub TrimbleTestBlocks()
'Get the editor object
Dim doc = AcApp.DocumentManager.MdiActiveDocument
Dim db = doc.Database
Dim ed = doc.Editor
Try
'Get Model Space Block Table Record
Dim mdlspace As BlockTableRecord = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead)
'Start the transaction
Using tm As Transaction = db.TransactionManager.StartTransaction
'Cycle through each object in modelspace
For Each objid As ObjectId In mdlspace
'If the object is a Pipe Object then add a block to the end of it
If objid.ObjectClass.Name = "AecdbPipe" Then
'At this point we know the object is a pipe so create a reference to it.
Dim mpipe As Pipe = tm.GetObject(objid, OpenMode.ForRead, True)
'Get the endpoint of the pipe
Dim PipeEndpoint As Point3d = mpipe.EndPoint
'Insert the block at the endpoint of the pipe
TrimbleInsertBlockAtPoint(INS250, PipeEndpoint, HYD250)
End If
Next
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
'TrimbleInsertBlockAtPoint(INS250, New Point3D(0, 0, 0), HYD250)
'TrimbleInsertBlockAtPoint(INS375, New Point3d(0, 10, 0), HYD375)
'TrimbleInsertBlockAtPoint(INS500, New Point3d(0, 20, 0), HYD500)
'TrimbleInsertBlockAtPoint(INS625, New Point3d(0, 30, 0), HYD625)
'TrimbleInsertBlockAtPoint(INS750, New Point3d(0, 40, 0), HYD750)
'TrimbleInsertBlockAtPoint(INS875, New Point3d(0, 50, 0), HYD875)
'TrimbleInsertBlockAtPoint(INS875, New Point3d(50, 50, 50), HYD875)
End Sub
This is the line that crashes on me
'Get Model Space Block Table Record
Dim mdlspace As BlockTableRecord = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead)
Does anyone have any ideas on why this is crashing the program? I just started programming dotnet this weekend and my head is starting to explode.
My end goal is to cycle through every pipe in model space. If the pipe belongs to a specified system definition then find the pipe size and insert a corresponding block on the endpoint of the pipe. I then want to export the blocks to a new drawing to be imported into a trimble unit for locating inserts on a deck.
Thanks for any help in advance.
Solved! Go to Solution.