Am I along the correct workflow path here?
I want to insert a drawing as a block into my current drawing.
Before I start writing code I want to make sure I understand the steps.
Open Transaction
Wblock Drawing to Temp Database
Now have my New BlockTableRecord Object
Copy BlockTableRecord to ActiveDwg.Database
Create New BlockReference
Add attributes
Set Scale Properties
Set Insertion Point
Set Rotation
Append BlockReference to Database
Commit Transaction
Am I missing any of the steps?
Is this how I would imidate the old VBA modelspace.insertblock(myPoint, "C:\path\path\path\block.dwg",1,1,1,0)
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
What about Database.Insert method?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Yes!
I think that will work.
AutoCAD help says:
This function mimics the AutoCAD INSERT command. First a new block table record is created in the database executing this function. This new block table record is given the name pointed to by blockName. Then, all the Model Space entities in the database pointed to by dataBase are copied into the new block table record.
Thank you.
Here's some code for people after me.
Public Shared Sub InsertInstrumentBlock() Dim gstrc_InstrumentBubbleBlock_FilePath As String = "C:\myblock.dwg" Dim BlockName As String = "Field Instrument" Dim myDwg As Document = Application.DocumentManager.MdiActiveDocument Using myTrans As Transaction = myDwg.TransactionManager.StartTransaction '<<Get Block From Drawing>> 'Read Block Drawing's Database Dim BlkDwgDB As New Database(False, False) BlkDwgDB.ReadDwgFile(gstrc_InstrumentBubbleBlock_FilePath, System.IO.FileShare.Read, True, "") 'Insert Block, Get ObjectID Dim id As ObjectId = mydwg.Database.Insert(BlockName, BlkDwgDB, False) '<<Insert BlockDefinition Into Specific Place on ModelSpace/PaperSpace>> 'Open the database for Write Dim myBT As BlockTable = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead) Dim myModelSpace As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite) 'Block Table Record (Block Definitions) Dim myBlockDef As BlockTableRecord = id.GetObject(OpenMode.ForWrite) Dim InsPt As New Point3d(0,0,0) 'Block References (Insertions of Blocks into Drawing Space) Dim myBlockRef As New DatabaseServices.BlockReference(InsPt, myBT(BlockName)) myBlockRef.ScaleFactors = New Geometry.Scale3d(1, 1, 1) myModelSpace.AppendEntity(myBlockRef) myTrans.AddNewlyCreatedDBObject(myBlockRef, True) 'Append Attribute References to the BlockReference Dim myAttColl As DatabaseServices.AttributeCollection Dim myEntID As ObjectId Dim myEnt As DatabaseServices.Entity myAttColl = myBlockRef.AttributeCollection For Each myEntID In myBlockDef myEnt = myEntID.GetObject(OpenMode.ForWrite) If TypeOf myEnt Is DatabaseServices.AttributeDefinition Then Dim myAttDef As DatabaseServices.AttributeDefinition = _ CType(myEnt, AttributeDefinition) Dim myAttRef As New DatabaseServices.AttributeReference myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform) myAttColl.AppendAttribute(myAttRef) myTrans.AddNewlyCreatedDBObject(myAttRef, True) End If Next 'Commit the Transaction myTrans.Commit() End Using End Sub
You forgot to skip the constant attributes
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
@Anonymous wrote:
Constant Attributes?
What's that? Can you tell me more please.
If AttributeDefinition.Constant = True then you have not add this attribute to attribute collection.
More detailes about constant attribute definition: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%202010%20User%20Documentation/index.html?url=WS1a9193826455f5ffa23ce210c4a30acaf-5142.htm,topicNumber=d0e197887
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Can't find what you're looking for? Ask the community or share your knowledge.