Using MInsert Block Objects

An MInsertBlock object contains a planar array of block references in rows and columns. This section tells how to add and modify MInsertBlock objects.

The AddMInsertBlock method works much like InsertBlock, except that the resulting entity is an MInsertBlock object. Just like InsertBlock, this method lets you specify a new entity's insertion point, scale, and rotation angle. It has additional parameters for the arrayed rows and columns. The method has the following syntax:

Set MInsertBlockObject = Object.AddMInsertBlock(InsertionPoint, BlockName, _ XScale, YScale, ZScale, RotationAngle, Rows, Columns, RowSpacing, _ ColumnSpacing)

Table 13-6 explains this method's parameters.

Table 13-6. The AddMInsertBlock Method's Parameters

Name

Data Type

Description

InsertionPoint

BlockName

Xscale

Yscale

Zscale

RotationAngle

Variant

String

Double

Double

Double

Double

A three-element array of doubles that specifies the 3-D WCS coordinates where the Xref will be inserted into the Object.

The name of a Block object in the Blocks collection or the path and file name for an AutoCAD drawing file to import.

A scaling factor for Negative numbers

A scaling factor for Negative numbers

A scaling factor for Negative numbers

The rotation angle relative to the WCS X-axis, expressed in radians.

the Xref's X direction. It may not be 0. mirror the insertion on this axis.

the Xref's Y direction. It may not be 0. mirror the insertion on this axis.

the Xref's Z direction. It may not be 0. mirror the insertion on this axis.

Continued

Table 13-6. Continued

Name

Data Type

Description

Rows

Long

A positive number that sets the number of rows.

Columns

Long

A positive number that sets the number of columns.

RowSpacing

Double

A nonzero number that specifies the spacing of rows in the array. A negative number creates rows in a negative X direction.

ColumnSpacing

Double

A nonzero number that specifies the spacing of columns in the array. A negative number creates columns in a negative Y direction.

The following example creates an MInsertBlock based on user input:

Public Sub TestAddMInsertBlock()

Dim strName As String

Dim varInsertionPoint As Variant

Dim dblX As Double

Dim dblY As Double

Dim dblZ As Double

Dim dR As Double

Dim lngNRows As Long

Dim lngNCols As Long

Dim dblSRows As Double

Dim dblSCols As Double

'' get input from user With ThisDrawing.Utility .InitializeUserInput 1

strName = .GetString(True, vbCr & "Block or file name: ") .InitializeUserInput 1

varInsertionPoint = .GetPoint(, vbCr & "Pick the insert point: ") .InitializeUserInput 1 + 2

dblX = .GetDistance(varInsertionPoint, vbCr & "X scale: ") .InitializeUserInput 1 + 2

dblY = .GetDistance(varInsertionPoint, vbCr & "Y scale: ") .InitializeUserInput 1 + 2

dblZ = .GetDistance(varInsertionPoint, vbCr & "Z scale: ") .InitializeUserInput 1

dR = .GetAngle(varInsertionPoint, vbCr & "Rotation angle: ") .InitializeUserInput 1 + 2 + 4 lngNRows = .GetInteger(vbCr & "Number of rows: ") .InitializeUserInput 1 + 2 + 4

lngNCols = .GetInteger(vbCr & "Number of columns: ") .InitializeUserInput 1 + 2

dblSRows = .GetDistance(varInsertionPoint, vbCr & "Row spacing: ") .InitializeUserInput 1 + 2

dblSCols = .GetDistance(varInsertionPoint, vbCr & "Column spacing: ") End With

'' create the object

ThisDrawing.ModelSpace.AddMInsertBlock varInsertionPoint, strName, _

dblX, dblY, dblZ, dR, lngNRows, lngNCols, dblSRows, dblSCols

End Sub

While the MInsertBlock object is similar to a BlockReference, because it's an array, it has these extra properties: Row, Column, RowSpacing, and ColumnSpacing.

The following example adjusts an MInsertBlock object's array properties. Try it on the object you created in the previous example.

Public Sub TestEditobjMInsertBlock()

Dim objMInsert As AcadMInsertBlock

Dim varPick As Variant

Dim lngNRows As Long

Dim lngNCols As Long

Dim dblSRows As Double

Dim dblSCols As Double

On Error Resume Next

'' get an entity and input from user With ThisDrawing.Utility

.GetEntity objMInsert, varPick, vbCr & "Pick an MInsert: " If objMInsert Is Nothing Then

MsgBox "You did not choose an MInsertBlock object" Exit Sub End If

.InitializeUserInput 1 + 2 + 4

lngNRows = .GetInteger(vbCr & "Number of rows: ")

.InitializeUserInput 1 + 2 + 4

lngNCols = .GetInteger(vbCr & "Number of columns: ") .InitializeUserInput 1 + 2

dblSRows = .GetDistance(varPick, vbCr & "Row spacing: ") .InitializeUserInput 1 + 2

dblSCols = .GetDistance(varPick, vbCr & "Column spacing: ") End With

'' update the objMInsert With objMInsert

.Rows = lngNRows .Columns = lngNCols .RowSpacing = dblSRows .ColumnSpacing = dblSCols .Update End With End Sub

Was this article helpful?

0 0

Post a comment