Cells

From Microstation VBA Wiki
Revision as of 13:34, 5 August 2010 by Ted (talk | contribs)
Jump to: navigation, search

Placing a cells is similar to placing lines in that both are elements. First you store the cell into a variable then you put that variable into the drawing.

Dim oCell as CellElement

It makes sense that you would need a point defined just like when your draw a line. But you also have to have a special kind of point called a scaling point and because you can bring a cell in at an angle, you also need a rotation matrix. If you want to keep it simple and bring the cell in at a scale of one with no rotation you can set up a point variable and a matrix and then set them to some standard values like this:

Dim ptScale As Point3d
Dim oMatrix As Matrix3d

ptScale = ActiveSettings.Scale
oMatrix = Matrix3dIdentity

Now you are ready to place a cell. Assuming the correct cell library is attached (should probably check first), you should be able to store a cell (in this example a cell named "AR34") in the oCell cell element you dimensioned earlier, and then add it to the drawing:

Set oCell = CreateCellElement2("AR34", ptStart, ptScale, False, oMatrix)
ActiveModelReference.AddElement oCell

Rotation

To rotate the cell, you have to come up with a rotation matrix variable different from Matrix3dIdentity. Fortunately there is a command that will create a basic rotation matrix given an angle in radians and the axis about which you want to rotate. For 2D drawings, that axis will always be Z which is indicated by the number 2.

oMatrix = Matrix3dFromAxisAndRotationAngle(2, Radians(180))

Now you can place the cell using oMatrix and it will be rotated.