making a block

making a block

Anonymous
Not applicable
121 Views
3 Replies
Message 1 of 4

making a block

Anonymous
Not applicable
Hello Group:
I had this code working in another routine. It makes a block
now it refuses to run, and throws an error 'type mismatch'
I've tried everything, what am I doing wrong here? Thanks in
advance
this is for release14, vba
thanks

If blkexist = False Then
Dim nwblk As AcadBlock
Dim tag1, tag2, tag3, tag4, def1, def2, def3, def4 As String
Dim blkinpnt1(0 To 2) As Double
blkinpnt1(0) = 0#: blkinpnt1(1) = 0#: blkinpnt1(2) = 0#
Dim blkinpnt2(0 To 2) As Double
blkinpnt2(0) = 0#: blkinpnt2(1) = 1#: blkinpnt2(2) = 0#
Dim blkinpnt3(0 To 2) As Double
blkinpnt3(0) = 0.0347222: blkinpnt3(1) = 1#: blkinpnt3(2) = 0#
Dim blkinpnt4(0 To 2) As Double
blkinpnt4(0) = 0.0347222: blkinpnt4(1) = 0#: blkinpnt4(2) = 0#
Set nwblk = ThisDrawing.Blocks.Add(blkinpnt1, "door")
Set nwblk = nwblk.AddLine(blkinpnt1, blkinpnt2)
Set nwblk = nwblk.AddLine(blkinpnt2, blkinpnt3)
Set nwblk = nwblk.AddLine(blkinpnt3, blkinpnt4)
Set nwblk = nwblk.AddLine(blkinpnt4, blkinpnt1)
Set nwblk = nwblk.AddArc(blkinpnt1, 1#, 0, 1.570796)
End If
0 Likes
122 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
The error is in these lines :

Set nwblk = nwblk.AddLine(blkinpnt1, blkinpnt2)

The AddLine method returns a Line object and you are trying to assign it
to a BlockObject.

Solution :
dim MyLine as AcadLine
dim MyArc as AcadArc

Set MyLine = nwblk.AddLine(blkinpnt1, blkinpnt2)
Set MyArc = nwblk.AddArc(....etc)

Regards,

Arno van Eeuwen

Andy wrote:

> Hello Group:
> I had this code working in another routine. It makes a block
> now it refuses to run, and throws an error 'type mismatch'
> I've tried everything, what am I doing wrong here? Thanks in
> advance
> this is for release14, vba
> thanks
>
> If blkexist = False Then
> Dim nwblk As AcadBlock
> Dim tag1, tag2, tag3, tag4, def1, def2, def3, def4 As String
> Dim blkinpnt1(0 To 2) As Double
> blkinpnt1(0) = 0#: blkinpnt1(1) = 0#: blkinpnt1(2) = 0#
> Dim blkinpnt2(0 To 2) As Double
> blkinpnt2(0) = 0#: blkinpnt2(1) = 1#: blkinpnt2(2) = 0#
> Dim blkinpnt3(0 To 2) As Double
> blkinpnt3(0) = 0.0347222: blkinpnt3(1) = 1#: blkinpnt3(2) = 0#
> Dim blkinpnt4(0 To 2) As Double
> blkinpnt4(0) = 0.0347222: blkinpnt4(1) = 0#: blkinpnt4(2) = 0#
> Set nwblk = ThisDrawing.Blocks.Add(blkinpnt1, "door")
> Set nwblk = nwblk.AddLine(blkinpnt1, blkinpnt2)
> Set nwblk = nwblk.AddLine(blkinpnt2, blkinpnt3)
> Set nwblk = nwblk.AddLine(blkinpnt3, blkinpnt4)
> Set nwblk = nwblk.AddLine(blkinpnt4, blkinpnt1)
> Set nwblk = nwblk.AddArc(blkinpnt1, 1#, 0, 1.570796)
> End If
0 Likes
Message 3 of 4

Anonymous
Not applicable
Hi Andy,
I am a novice at this myself, but the literature I have read
would suggest that the code should look something like this:-

Dim objLine As AcadLine
Dim objArc As AcadArc

Set nwblk = ThisDrawing.Blocks.Add(blkinpnt1, "door")
Set objLine = nwblk.AddLine(blkinpnt1, blkinpnt2)
Set objLine = nwblk.AddLine(blkinpnt2, blkinpnt3)
Set objLine = nwblk.AddLine(blkinpnt3, blkinpnt4)
Set objLine = nwblk.AddLine(blkinpnt4, blkinpnt1)
Set objArc = nwblk.AddArc(blkinpnt1, 1#, 0, 1.570796)
End If

Let me know if it works.

Cheers, John.

Andy wrote in message <387655E4.4B86277@bellsouth.net>...
>Hello Group:
> I had this code working in another routine. It makes a block
>now it refuses to run, and throws an error 'type mismatch'
>I've tried everything, what am I doing wrong here? Thanks in
>advance
>this is for release14, vba
>thanks
>
>If blkexist = False Then
>Dim nwblk As AcadBlock
>Dim tag1, tag2, tag3, tag4, def1, def2, def3, def4 As String
>Dim blkinpnt1(0 To 2) As Double
>blkinpnt1(0) = 0#: blkinpnt1(1) = 0#: blkinpnt1(2) = 0#
>Dim blkinpnt2(0 To 2) As Double
>blkinpnt2(0) = 0#: blkinpnt2(1) = 1#: blkinpnt2(2) = 0#
>Dim blkinpnt3(0 To 2) As Double
>blkinpnt3(0) = 0.0347222: blkinpnt3(1) = 1#: blkinpnt3(2) = 0#
>Dim blkinpnt4(0 To 2) As Double
>blkinpnt4(0) = 0.0347222: blkinpnt4(1) = 0#: blkinpnt4(2) = 0#
>Set nwblk = ThisDrawing.Blocks.Add(blkinpnt1, "door")
>Set nwblk = nwblk.AddLine(blkinpnt1, blkinpnt2)
>Set nwblk = nwblk.AddLine(blkinpnt2, blkinpnt3)
>Set nwblk = nwblk.AddLine(blkinpnt3, blkinpnt4)
>Set nwblk = nwblk.AddLine(blkinpnt4, blkinpnt1)
>Set nwblk = nwblk.AddArc(blkinpnt1, 1#, 0, 1.570796)
>End If
>
0 Likes
Message 4 of 4

Anonymous
Not applicable
You can ignore the return values from any of the Add methods if you do not
need to reference them after their creation. Makes for a lot fewer
variables.

So this:
Set objLine = nwblk.AddLine(blkinpnt2, blkinpnt3)

Becomes this:
nwblk.AddLine blkinpnt2, blkinpnt3
0 Likes