Author Topic: inserting access recordset into drawing  (Read 2559 times)

0 Members and 1 Guest are viewing this topic.

whom2be

  • Guest
inserting access recordset into drawing
« on: December 29, 2004, 09:58:22 AM »
Hello all...
I am new to the site, t-bear recomended it to me.

I am trying to import records from tables in an access db.
I am able to connect to the database and create the recordsets from inside autocad. I am even able to insert the records into the drawing like "I" want.

Problem is that its not what "he" wants.

What I need is this:

After the user selects all the information from my custom user form the data contained in the recordset should hover under the mouse untill he clicks where he wants to paste it in the drawing. Each recordset has many rows and many columns.

I am currently using the following:
ThisDrawing.PaperSpace.AddText fldPart, P, Height
(There are several of these statements, one for each column)

With this I use a for or a while loop and insert each row and column into the drawing piece by piece and change the insertpoint for each.


Any help or advice would be greatly appreaciated

BAshworth

  • Guest
inserting access recordset into drawing
« Reply #1 on: December 29, 2004, 12:24:45 PM »
Greetings Whom2be.

There are a couple of directions that you can go here.  Neither one is as easy or concise as I'm sure you were hoping for.

One direction, would be to go ahead and create your text from the recordset inside a new drawing, save it, then use a send command string to startup the ddinsert command.  User gets the familiarity of the block insertion, but it's not as tight of a program, and you lose some control over what happens.

Another direction, would be to do the same as above as far as creating the table in a separate dwg file, and inserting it as a block (which you can explode later) but use a Ghost Block insertion routine to facilitate what the client is asking for.

That routine is not located on this site.  It's on one called Cadvault.com.  Go there, register, and run a search for "Ghost block" It was written by a gentleman who is a member of that site.

Good luck, and drop back in if you have any other questions.

whom2be

  • Guest
inserting access recordset into drawing
« Reply #2 on: December 30, 2004, 10:17:38 AM »
Thank you BAshworth

That gave me a good start and some good ideas. I have it very close to the way I want it now.

BUT... I am having a couple of other problems. Here is a piece of my code:
--------------------------------------------------------------------------------------
    Set newBlock = ThisDrawing.Blocks.Add(pt1, "txtBlock")
        For i = 0 To iSelected - 1
            If lbDrawings.Selected(i) Then
           
                strDrawing = ("select [drawing id]
                                      from drawings
                        where [drawing id] = '" & lbDrawings.Column(0, i) & "'")

                Set rs = db.OpenRecordset(strDrawing, dbOpenDynaset)
                Set flddrawing = rs.Fields("drawing id")
           
                rs.MoveFirst
                While Not rs.EOF
   
                    Set txtObj = newBlock.AddText(flddrawing, pt1, 0.09)                    pt1(1) = pt1(1) - 0.1696
                    rs.MoveNext
                Wend
            End If
        Next
   
    ThisDrawing.PaperSpace.InsertBlock pt, "txtBlock", 1, 1, 1, 0
------------------------------------------------------------------------------------

Ok questions are:
1. how do I delete the block I created or at least clear it.
          I have tried
                  newBlock.delete  and
                 ThisDrawing.Blocks("txtBlock").delete
          I get object required errors

2.Can I format the text before or after I add it to the block
   I need to set the font, width, and bold.
      For the font I can use
        ThisDrawing.ActiveTextStyle.SetFont "romans", False, False, 1, 1
        but I dont want to do a global font change.


Any help or advice would be greatly appreaciated

BAshworth

  • Guest
inserting access recordset into drawing
« Reply #3 on: December 30, 2004, 11:41:26 AM »
Glad it's coming along.

For your first question.  You are adding a member to the Blocks collection.  There is no actual block created in model space when you add to this collection.  If you wanted one, you would be using the BlockReferences collection.  There is no need to remove it from the collection.

As for the font.  When you add the text, you could use the properties of textObj to adjust the font, width, height, etc... after you use the AddText method.

whom2be

  • Guest
inserting access recordset into drawing
« Reply #4 on: December 30, 2004, 12:32:50 PM »
Hello and thanks...

The reason I need to delete or clear the block is because every time I run the module it keeps adding new information on top of the old information. So what I need is when I start the procedure it first deletes or clears the block then add the new imformation.

As it is now everytime I run it to test it I have to create a new block to get an empty one. I keep doing:
 Set newBlock = ThisDrawing.Blocks.Add(pt, "txtBlock12")
then the next time I run it to test it
Set newBlock = ThisDrawing.Blocks.Add(pt, "txtBlock13")


And for the text in the block I can do things like this:
          Set txtObj = newBlock.AddText(flddrawing, ptDrawing, 0.09)
           txtObj.Color = acBlue

But there is no txtObj.Width option, or its called something I am unfimuliar with.
Once I insert the block and explode it I can right click and go to properties and set the width but that kinda defeats the automation with vba.

BAshworth

  • Guest
inserting access recordset into drawing
« Reply #5 on: December 30, 2004, 02:45:20 PM »
Do you need to keep it a block?  I thought you were inserting just stand-alone text before, and that you were going to explode the block after you were done inserting it.  Anyway...  I'll have to do a little research on that one.  Are you calling the delete method from within the same sub, or later on down the line?

As for the text.  Might I recommend creating a new style for this.  Some of the things you are doing (bold for example) are really only available from within the style.

If no, width is the scalefactor property (I believe)