23.09.2013 Views

Dia 1 - CAD College

Dia 1 - CAD College

Dia 1 - CAD College

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Public Function InsertBlock(ByVal DatabaseIn As Database, _<br />

ByVal BTRToAddTo As String,ByVal InsPt As Geometry.Point3d, _<br />

ByVal BlockName As String,ByVal XScale As Double,ByVal YScale As Double,_<br />

ByVal ZScale As Double) As DatabaseServices.ObjectId<br />

Using myTrans As Transaction=DatabaseIn.TransactionManager.StartTransaction<br />

Dim myBlockTable As BlockTable= _<br />

DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead)<br />

If myBlockTable.Has(BlockName) = False Then<br />

Return Nothing<br />

1<br />

End If<br />

If myBlockTable.Has(BTRToAddTo) = False Then<br />

Return Nothing<br />

End If<br />

Dim myBlockDef As BlockTableRecord = _<br />

myBlockTable(BlockName).GetObject(OpenMode.ForRead)<br />

Dim myBlockTableRecord As BlockTableRecord = _<br />

myBlockTable(BTRToAddTo).GetObject(OpenMode.ForWrite)<br />

Dim myBlockRef As New BlockReference(InsPt, myBlockDef.Id)<br />

myBlockRef.ScaleFactors = New Geometry.Scale3d(XScale, YScale, ZScale)<br />

myBlockTableRecord.AppendEntity(myBlockRef)<br />

myTrans.AddNewlyCreatedDBObject(myBlockRef, True)<br />

Dim myAttColl As DatabaseServices.AttributeCollection = _<br />

myBlockRef.AttributeCollection<br />

For Each myEntID As ObjectId In myBlockDef<br />

Dim myEnt As Entity = myEntID.GetObject(OpenMode.ForRead)<br />

If TypeOf myEnt Is DatabaseServices.AttributeDefinition Then<br />

Dim myAttDef As DatabaseServices.AttributeDefinition = myEnt<br />

Dim myAttRef As New DatabaseServices.AttributeReference<br />

myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform)<br />

myAttColl.AppendAttribute(myAttRef)<br />

myTrans.AddNewlyCreatedDBObject(myAttRef, True)<br />

End If<br />

Next<br />

myTrans.Commit()<br />

Return myBlockRef.Id<br />

End Using<br />

End Function<br />

1- We are able to specifying the BlockTableRecord which we want to insert the block in the<br />

ModelSpace, PaperSpace, or even another BlockDefinition (see page 40)<br />

2- We loops through each entity in a Block Definition, looking for an AttributeDefinition entity.<br />

If we find an AttributeDefinition, we create a new AttributeReference based on the Definition<br />

and append the AttributeReference to the AttributeCollection of the BlockReference.<br />

But what dose this main, is it Maine that Attribute like akind of Block in Block, I think it’s like<br />

that.<br />

What important to me is BlockReference which is in another word Block name and the<br />

AttributeReference they are not the same and that affect on the SelectionFilter Criterium.<br />

In the next page a practicl exampel.<br />

16/12/2010 ED<strong>CAD</strong>1.0 HBO-Traject 2010 48<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!