insert block with attributes by user from VBA
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
insert block with attributes by user from VBA

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
MiD-AwE
Guest





Posted: Tue Jan 11, 2005 4:31 am    Post subject: insert block with attributes by user from VBA Reply with quote

Before you decide to scold me, I must mention that I'm new to VBA yet learning quickly, and I've spent the last hour reading everything on this ng about blocks and attributes though I'm not understanding enough to answer my own question. OK, I have written a simple VBA proggie that gets information from user about what block that they'd like to insert to model space and then it should allow them to pre-answer attribute prompts (due to old block and new automation).
ex. window pops-up and user chooses a block with 6 attributes all requiring PVC sizes to display in block. I then want to allow the user to define these PVC sizes. after which the user clicks <OK> and the block is inserted with all attribute prompts answered.

I already tried ThisDrawing.SendCommand and just sent all string data to the command line separated by spaces but it doesn't work or maybe I'm just doing it wrong. I am now just inserting the block and then activating this LISP routine (COMMAND "DDATTE" "" "LAST")

I got the impression from other topics on this ng that it is possible to send the ThisDrawing.SendCommand with the attributes already defined before the block is actually inserted or maybe I misunderstood that as well.

Please, someone help by at least giving me some clue that I can read to better understand how I can do this. I'll post any code if necessary. Thanks, in advance.

Back to top
Laurie Comerford
Guest





Posted: Tue Jan 11, 2005 5:13 am    Post subject: Re: insert block with attributes by user from VBA Reply with quote

Hi,

For this exercise, forget the "Sendcommand" process. Use the APIs to add
the blocks and populate the attributes.

There is sample code for doing this supplied with the software, and you
should find it quite straight forward to modify that code to suit your
specific needs.

If you have any queries from the sample code, then post again.

--


Laurie Comerford
CADApps
www.cadapps.com.au


"MiD-AwE" <nospam@address.withheld> wrote in message
news:22109171.1105399894365.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Before you decide to scold me, I must mention that I'm new to VBA yet
learning quickly, and I've spent the last hour reading everything on this ng

about blocks and attributes though I'm not understanding enough to answer my
own question. OK, I have written a simple VBA proggie that gets information
from user about what block that they'd like to insert to model space and
then it should allow them to pre-answer attribute prompts (due to old block
and new automation).
Quote:
ex. window pops-up and user chooses a block with 6 attributes all
requiring PVC sizes to display in block. I then want to allow the user to

define these PVC sizes. after which the user clicks <OK> and the block is
inserted with all attribute prompts answered.
Quote:

I already tried ThisDrawing.SendCommand and just sent all string data to
the command line separated by spaces but it doesn't work or maybe I'm just

doing it wrong. I am now just inserting the block and then activating this
LISP routine (COMMAND "DDATTE" "" "LAST")
Quote:

I got the impression from other topics on this ng that it is possible to
send the ThisDrawing.SendCommand with the attributes already defined before

the block is actually inserted or maybe I misunderstood that as well.
Quote:

Please, someone help by at least giving me some clue that I can read to
better understand how I can do this. I'll post any code if necessary.

Thanks, in advance.
Back to top
Jeff Mishler
Guest





Posted: Tue Jan 11, 2005 5:19 am    Post subject: Re: insert block with attributes by user from VBA Reply with quote

Here's a small code snippet that should get you pointed in the right
direction, based on Laurie's suggestion:

Code:

Option Explicit

Sub Example_InsertBlock()
    Dim insertionPnt(0 To 2) As Double
    Dim blockRef As AcadBlockReference
    Dim blockName As String
    Dim attRefs As Variant
    Dim attRef As AcadAttributeReference
    Dim I As Long

    blockName = "TDG" 'Change this to the block you want
    insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
    Set blockRef = ThisDrawing.ModelSpace.InsertBlock(insertionPnt,
blockName, 1#, 1#, 1#, 0)

    If blockRef.HasAttributes = True Then
        attRefs = blockRef.GetAttributes
        For I = 0 To UBound(attRefs)
            Set attRef = attRefs(I)
            'do your stuff with the values here
        Next I
    End If
End Sub


--
Jeff
check out www.cadvault.com
"MiD-AwE" <nospam@address.withheld> wrote in message
news:22109171.1105399894365.JavaMail.jive@jiveforum1.autodesk.com...
Quote:
Before you decide to scold me, I must mention that I'm new to VBA yet
learning quickly, and I've spent the last hour reading everything on this
ng about blocks and attributes though I'm not understanding enough to
answer my own question. > Please, someone help by at least giving me some
clue that I can read to better understand how I can do this. I'll post any
code if necessary. Thanks, in advance.


Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB