How in the world do I insert a block and assign values to its attributes as I

How in the world do I insert a block and assign values to its attributes as I

Anonymous
Not applicable
193 Views
2 Replies
Message 1 of 3

How in the world do I insert a block and assign values to its attributes as I

Anonymous
Not applicable

How in the world do I insert a block and assign
values to its attributes as I insert it?


I can't find it anywhere.


 


 


any help


 


joseguia


janitor

0 Likes
194 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Here is what I am using, temporarily, I do not like this method because
there is no method to the numbering in the array, but it works, for this
drawing. If you find a more universal way, aka, a way to call the
attributes by their tag name as opposed to an array number, please let me
know, I will be very grateful. Thanks

This is inserting a block in modelspace, and another block in paperspace.
This is code from VB6.

AppActivate AcadApp.Caption
Set thisdrawing = AcadApp.ActiveDocument

Dim insertionPnt(0 To 2) As Double

' Insert the block
Dim blockRefObj As AcadBlockReference
insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0
Set blockRefObj = thisdrawing.ModelSpace.InsertBlock(insertionPnt,
"BLOCK", 1#, 1#, 1#, 0)

' Get the attributes for the block reference
Dim varAttributes As Variant
varAttributes = blockRefObj.GetAttributes

' Move the attribute tags and values into a string
Dim strAttributes As String
Dim I As Integer
For I = LBound(varAttributes) To UBound(varAttributes)
strAttributes = strAttributes & " Tag: " &
varAttributes(I).TagString & _
" Value: " & varAttributes(I).TextString & " "
Next


varAttributes(0).TextString = txtlooper.Text
varAttributes(1).TextString = txtneedle.Text
varAttributes(2).TextString = txtjig.Text
varAttributes(3).TextString = txtcage.Text
varAttributes(4).TextString = txtthreadtype.Text
varAttributes(5).TextString = txtdiscnumberreqired.Text
varAttributes(6).TextString = txtdiscpartnumber.Text
varAttributes(7).TextString = txtfabric.Text
varAttributes(8).TextString = txtneedle.Text
varAttributes(9).TextString = txtfabric.Text
varAttributes(10).TextString = txtOALtolerance.Text
varAttributes(11).TextString = txtpinch.Text
varAttributes(12).TextString = txtOAL.Text
varAttributes(13).TextString = txtdiscdia.Text
varAttributes(14).TextString = txtcurrentrev.Text
varAttributes(15).TextString = txtpartnumber.Text
varAttributes(16).TextString = txtfinish.Text
varAttributes(17).TextString = txtflatwidth.Text
varAttributes(18).TextString = txtthreadtype.Text
varAttributes(19).TextString = txtcutlength.Text
varAttributes(20).TextString = txtslitwidth.Text
varAttributes(21).TextString = txtfinishdirection.Text
varAttributes(22).TextString = txtspecialinstructions.Text
varAttributes(23).TextString = txtbagsperbox.Text
varAttributes(24).TextString = txtbagsperbox.Text


' Insert the block
Dim blockRefObj2 As AcadBlockReference
insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0
Set blockRefObj2 = thisdrawing.PaperSpace.InsertBlock(insertionPnt,
"TITLEBLOCK", 1#, 1#, 1#, 0)

' Get the attributes for the block reference
Dim varAttributes2 As Variant
varAttributes2 = blockRefObj2.GetAttributes

' Move the attribute tags and values into a string
Dim strAttributes2 As String
For I = LBound(varAttributes2) To UBound(varAttributes2)
strAttributes2 = strAttributes2 & " Tag: " &
varAttributes2(I).TagString & _
" Value: " & varAttributes2(I).TextString & " "
Next


varAttributes2(0).TextString = txtpartnumber.Text
varAttributes2(1).TextString = txtconstruction.Text
varAttributes2(2).TextString = txtdimensions.Text
varAttributes2(3).TextString = txttype.Text
varAttributes2(4).TextString = txtOEM.Text
varAttributes2(5).TextString = txtfabric.Text
varAttributes2(6).TextString = txtcurrentrev.Text
varAttributes2(7).TextString = txtrevdate.Text
varAttributes2(8).TextString = txtcurrentrev.Text
varAttributes2(9).TextString = txtrevby.Text
varAttributes2(10).TextString = txtchangesmade.Text
0 Likes
Message 3 of 3

Anonymous
Not applicable
This is almost the way I did it, except where you use an array to assign
your values, I have a procedure that I send the blockreference, the
tagstring and the value I want to set the attribuite to as follows:


Private Sub SetText(objBlockRef As Object, strTag As String, strValue As
String)
On Error GoTo STERR:

Dim i As Integer
Dim objAttributes As Variant

objAttributes = objBlockRef.GetAttributes

For i = 0 To UBound(objAttributes)
'Debug.Print objAttributes(i).TagString
If objAttributes(i).TagString = strTag Then
objAttributes(i).TextString = strValue
Exit For
End If
Next i

'Stop
Exit Sub
STERR:
Err.Raise Err
Exit Sub
End Sub

This way you do not have to know which index is what when you get the
attributes from the blockreference. So now I have something like:

dblInsertPt(0) = 0: dblInsertPt(1) = 0: dblInsertPt(2) = 0
Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(dblInsertPt,
", 1, 1, 1, 0)
SetText objBlockRef, ,
SetText objBlockRef, ,
SetText objBlockRef, ,

and so on......

Hope this helps,

Jody Whitfill


"Brad" wrote in message
news:11169335AEFA84D127636DC4158B92C5@in.WebX.maYIadrTaRb...
> Here is what I am using, temporarily, I do not like this method because
> there is no method to the numbering in the array, but it works, for this
> drawing. If you find a more universal way, aka, a way to call the
> attributes by their tag name as opposed to an array number, please let me
> know, I will be very grateful. Thanks
>
> This is inserting a block in modelspace, and another block in paperspace.
> This is code from VB6.
>
> AppActivate AcadApp.Caption
> Set thisdrawing = AcadApp.ActiveDocument
>
> Dim insertionPnt(0 To 2) As Double
>
> ' Insert the block
> Dim blockRefObj As AcadBlockReference
> insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0
> Set blockRefObj = thisdrawing.ModelSpace.InsertBlock(insertionPnt,
> "BLOCK", 1#, 1#, 1#, 0)
>
> ' Get the attributes for the block reference
> Dim varAttributes As Variant
> varAttributes = blockRefObj.GetAttributes
>
> ' Move the attribute tags and values into a string
> Dim strAttributes As String
> Dim I As Integer
> For I = LBound(varAttributes) To UBound(varAttributes)
> strAttributes = strAttributes & " Tag: " &
> varAttributes(I).TagString & _
> " Value: " & varAttributes(I).TextString & "
"
> Next
>
>
> varAttributes(0).TextString = txtlooper.Text
> varAttributes(1).TextString = txtneedle.Text
> varAttributes(2).TextString = txtjig.Text
> varAttributes(3).TextString = txtcage.Text
> varAttributes(4).TextString = txtthreadtype.Text
> varAttributes(5).TextString = txtdiscnumberreqired.Text
> varAttributes(6).TextString = txtdiscpartnumber.Text
> varAttributes(7).TextString = txtfabric.Text
> varAttributes(8).TextString = txtneedle.Text
> varAttributes(9).TextString = txtfabric.Text
> varAttributes(10).TextString = txtOALtolerance.Text
> varAttributes(11).TextString = txtpinch.Text
> varAttributes(12).TextString = txtOAL.Text
> varAttributes(13).TextString = txtdiscdia.Text
> varAttributes(14).TextString = txtcurrentrev.Text
> varAttributes(15).TextString = txtpartnumber.Text
> varAttributes(16).TextString = txtfinish.Text
> varAttributes(17).TextString = txtflatwidth.Text
> varAttributes(18).TextString = txtthreadtype.Text
> varAttributes(19).TextString = txtcutlength.Text
> varAttributes(20).TextString = txtslitwidth.Text
> varAttributes(21).TextString = txtfinishdirection.Text
> varAttributes(22).TextString = txtspecialinstructions.Text
> varAttributes(23).TextString = txtbagsperbox.Text
> varAttributes(24).TextString = txtbagsperbox.Text
>
>
> ' Insert the block
> Dim blockRefObj2 As AcadBlockReference
> insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0
> Set blockRefObj2 = thisdrawing.PaperSpace.InsertBlock(insertionPnt,
> "TITLEBLOCK", 1#, 1#, 1#, 0)
>
> ' Get the attributes for the block reference
> Dim varAttributes2 As Variant
> varAttributes2 = blockRefObj2.GetAttributes
>
> ' Move the attribute tags and values into a string
> Dim strAttributes2 As String
> For I = LBound(varAttributes2) To UBound(varAttributes2)
> strAttributes2 = strAttributes2 & " Tag: " &
> varAttributes2(I).TagString & _
> " Value: " & varAttributes2(I).TextString & "
"
> Next
>
>
> varAttributes2(0).TextString = txtpartnumber.Text
> varAttributes2(1).TextString = txtconstruction.Text
> varAttributes2(2).TextString = txtdimensions.Text
> varAttributes2(3).TextString = txttype.Text
> varAttributes2(4).TextString = txtOEM.Text
> varAttributes2(5).TextString = txtfabric.Text
> varAttributes2(6).TextString = txtcurrentrev.Text
> varAttributes2(7).TextString = txtrevdate.Text
> varAttributes2(8).TextString = txtcurrentrev.Text
> varAttributes2(9).TextString = txtrevby.Text
> varAttributes2(10).TextString = txtchangesmade.Text
>
>
0 Likes