Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access output to Autocad 1

Status
Not open for further replies.

HanKleppe

Programmer
Mar 17, 2005
50
NL
Dear Forummembers,

After Todd, helped me great with im/exporting Attributes to Access I'm in the next step of my little program.

I have a button in Access. When I click it, it opens Autocad and opens the primary key, what is a pathname.

Code:
Dim X, Y
Y = "C:\Program Files\AutoCAD 2004\acad.exe " & [Forms]![Formulier1]![Tekst31]
X = Shell(Y, 1)
End Sub

Now I want Access to print. /p is usually by office programs but doesn't work in autocad.

I have also a field in the table containing the number of printing files. I want Autocad use this number to his printnumber.

Who can give me a kick in the good way?

Thanks!
 
Hi Todd,

It's in the Netherlands 21:38 and with a beer you create the best ideas :)
Maybe I can make a macro what runs the printingprogram.

Example:

-Open autocad

-Print code
loop=copies

Is this possible?

TIF
Han
 
Hi Todd,

Sorry for my long time being 'offline' I was busy with a lot of other projects.

I produced the following code, and it feels i'm very close...

Code:
AcadDoc.Plot.NumberOfCopies = "[Aantal]"
AcadDoc.Plot.PlotToDevice

'AcadDoc.Save
'AcadApplication.Quit

It give now a execution error. When I change "[Aantal]" for "2" it works perfect.

Maybe AutoCad needs to connect first to the database? That would be strange cause I'm running this part of the code in this code, so it is allready connected:

Code:
Public Sub ImportAttribs()
  '
  ' Title     : ImportAttribs
  '
  ' Version   : 1.0.0
  ' Author(s) : Todd Carpenter
  ' Created   : 04/15/2005 08:13:55 AM
  ' Last Edit : 04/15/2005 08:13:55 AM, TDC
  ' Copyright : (c)2005 Todd Carpenter
  '
  ' Description:
  ' ¯¯¯¯¯¯¯¯¯¯¯¯
  '   This routine is used to update or import attribute
  '   values from a database.
  '
  ' Additional files/functions required:
  ' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  '   1) AttribExtract
  '   2) BuildFilter
  '   3) Connect
  '   4) vbdPowerSet
  '
  ' Requires the following variables:
  ' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  '    * Input assignments
  '      1) AcadDoc    - Current AutoCAD drawing document must be global.
  '      2) cnnDataBse - Connection to database must be global.
  '      3) rstAttribs - Recordset to update or append to database, must be global.
  '
  ' Updates:
  ' ¯¯¯¯¯¯¯¯
  ' 04/15/2005 08:13:55 AM - 1.0.0 - TDC
  '    1) Initially created
  '
  ' Future considerations:
  ' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  '    1) None
  '
  ' ImportAttribs begins here:
  ' ——————————————————————————————————————————————————

  Dim ssTitleBlock As AcadSelectionSet  'Selection set containing the title block to export.
  Dim intData()    As Integer           'DXF integer code used to filter selection set.
  Dim varData()    As Variant           'DXF code description used to filter selection set.
  Dim varAttribs   As Variant           'Attribute array from title block.
  Dim intAttribCnt As Integer           'Attribute array upper and lower bounds.
  Dim fldAttribs   As ADODB.Field       'ADO fields from recordset for populating recordset.
  Dim strSearch    As String            'Pseudo Primary Key in case of duplicates.
  Dim result       As VbMsgBoxResult    'User prompted responses.
  Dim strTblName   As String            'Name of Access table to populate.

  ' Defaults.
  '
  strTblName = "toddiscool"
  Set AcadDoc = ThisDrawing ' Current drawing.
      
  ' Build the filter criteria.
  '
  BuildFilter intData, varData, -4, "<and", _
                                  0, "INSERT", _
                                  2, "Terrier kader", _
                                -4, "and>"
                                
  ' Ensure a selection set is not already in memory.
  '
  Set ssTitleBlock = vbdPowerSet("TBLOCK")
  
  ' Build the selection set.
  '
  ssTitleBlock.Select Mode:=acSelectionSetAll, FilterType:=intData, FilterData:=varData
  
  ' Was anything actually found?
  '
  If ssTitleBlock.Count = 0 Then
    ' The title block wasn't found, notify the user and exit.
    '
    MsgBox "A Standard title block wasn't found, please correct and try again."
    End
  End If
  
  ' Collect the attributes.
  '
  varAttribs = AttribExtract(ssTitleBlock(0))
    
  ' Connect to the title block database.
  '
  Connect "C:\Autocad\database.mdb", strTblName
  
  ' Walk the array and find the "Primary Key" field: DWGNUM
  '
  strSearch = ThisDrawing.Path & "\" & ThisDrawing.Name
  
  ' Now search the database, and locate the record to import.
  '
  rstAttribs.Find "[Locatie bestand]= '" & strSearch & "'"
  
  If rstAttribs.EOF Then
    ' blnDuplicate = False  ' No existing record found.
    MsgBox "No records found to update.  Please check the database and try again."
    Exit Sub
  End If
     
  ' Walk the array, comparing tag strings to field names,
  ' and populating or updating accordingly.
  '
  For intAttribCnt = LBound(varAttribs) To UBound(varAttribs)
    For Each fldAttribs In rstAttribs.Fields
      ' Does the tag string value match the field name?
      '
      If UCase(fldAttribs.Name) = UCase(varAttribs(intAttribCnt).TagString) Then
        ' Must have the right tag string mapped to the correct field name,
        ' update the field.
        '
        varAttribs(intAttribCnt).TextString = fldAttribs.Value
        Exit For
      End If
    Next fldAttribs
  Next intAttribCnt
      
  ssTitleBlock(0).Update
  
'-----------------------------------------------------------------------------------
  
AcadDoc.Plot.NumberOfCopies = "[Aantal]"
AcadDoc.Plot.PlotToDevice

'AcadDoc.Save
'AcadApplication.Quit

End Sub

TIF!

Han
 
Hi Han,

I know the feeling...

Change this:
Code:
AcadDoc.Plot.NumberOfCopies = "[Aantal]"

To:

Code:
AcadDoc.Plot.NumberOfCopies = rstAttribs.Fields("Aantal").Value

HTH
Todd
 
Hi Todd,

Lol, it's a wellknown worldwide feeling!
You're great! I'm gonna try it after the weekend!

Thanks a lot!

Han
 
Hi Todd,

Did you have a nice weekend?
My monday is perfect, the code is perfectly working!!!

Code:
AcadDoc.Plot.NumberOfCopies = rstAttribs.Fields("Aantal").Value
AcadDoc.Plot.PlotToDevice

'AcadDoc.Save
'AcadApplication.Quit

End Sub

Thanks a lot!!!
Han
 
Hi Todd,

I'm now building the structure, i'll update when I have news)

Han
 
Hi Todd,

I'm playing with my little program and I've 2 questions:

- I start AutoCAD with the following code:
Y = "C:\Program Files\AutoCAD 2004\acad.exe /nologo " & [Forms]![Formulier1]![Tekst31]

The're is also a switch to start automatically a script: /b with the scriptname. I use the script importattribs in acad.dvb Have you any acknowledge about this switch?

- When a field in access and autocad is empty the're is a space or something like that. When I change it, it changes correctly, but when I change it back to empty, the script gives a failure. When I try to past the little space, of do spacebar within the field it returns to empty.
Any Ideas?

TIF!
Han
 
Hi Han,

I know how to use it, that's about it.

The space issue is a little wierd. The spacebar on the keyboard should be fine, the only thing I can think of is maybe you should turn off or on Unicode compression in your field?

HTH
Todd
 
Hi Todd,

Do you know how to handle the switch /b so the script will run automatically. I can load the script when AutoCAD is openening, but the script will shutdown AutoCAD when it print and saved

How can I turn of that compression?

TIF
Han
 
Hi Han,

The script should take off running on its own, if your the script is shutting down, there is probably an error in the script - if you execute anything requiring user input, or any command generating a dialog box, or if you execute some other lisp, VBA, VB routine, the script stops, in some cases, you can issue the RESUME command and the script will pick back up.

The compression is set in the table design and you'll see a property labeled "Unicode compression"

HTH
Todd
 
Hi Todd,

Sorry for my bad explanation about the script. This is what the script do:
-import
-save
-exit

I loaded the script in acad.dvb like also the export script. Now I want a shortcut so autocad start automatically the script, saves and exit. So it's not allowed to run on every startup.
I saw the switch /b so maybe you can help me out.

The script is located at acad.dvb and the funtion is importatrribs (yes, it's your script :eek:))

TIF!
 
Ooohhh...

I thought the 'script' was a regular AutoCAD script! Now I get it!

Ok, here's what I would do. For my shortcut on my desktop, in the "Target" field, my command line would look like this:

Code:
"C:\Program Files\AutoCAD 2004\acad.exe" /nologo /b "import"

"import" is a script file, "import.scr" containing 1 line:

Code:
(command "VBARUN" "acad!importatrribs")

You may have to tweak the script file just a little, but you get the idea. The script file must be located in one of AutoCAD's support directories.

HTH
Todd
 
Hi Todd,

I guess you're the one with the most knowlegde at AutoCAD customazium (hope I spell it correct :)) How old/young are you?
I had to say I learned a lot in the past period.

You're solution is perfectly working in the shortcut. (I edit the scriptfile to add a , to simultain an enter)

But after that I try to implementate it in the total script:

Y = "C:\Program Files\AutoCAD 2004\acad.exe /b "import"" & [Forms]![AutoCAD Updater]![Tekst31]

It gives an syntaxiserror

After that I changed it to:
Y = "C:\Program Files\AutoCAD 2004\acad.exe /b ""import""" & [Forms]![AutoCAD Updater]![Tekst31]

Now it opens AutoCAD but it gives the following error:

"importC:\AutoCAD\Tekeningen\250000.dwg"
Invalid file name

After that I try to do it on a different way:

Y = "C:\Program Files\AutoCAD 2004\acad.exe" & [Forms]![AutoCAD Updater]![Tekst31]

AutoCAD.AcadApplication.RunMacro (Import)
and
AutoCAD.AcadApplication.RunMacro (acad.dvb!import)

But both times it gives an error.

Do you have a solution?

TIF!
 
Hi Todd,

I have the solution:
AutoCAD.AcadApplication.RunMacro ("acad.dvb!import")

When I run it separatelly it works, cause else AutoCAD is opening.
Do you know the code for waiting/delay of 6 seconds, or something?

TIF
Han
 
Hi Todd,

Oops I THOUGH I was smart :eek:)
So there's no solution from my side

TIF
Han
 
Hi Han,

Thanks for the kudos... and for what it's worth I'm 18 with 19 years experience!

Try this in your code:

Code:
chr(34) & "C:\Program Files\AutoCAD 2004\acad.exe" & chr(34) & " /b "& chr(34) & "import" & chr(34) & [Forms]![AutoCAD Updater]![Tekst31]

HTH
Todd
 
Hi Todd,

Means you're 37?

Code:
Private Function UpdateAutocad()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Chr (34) & "C:\Program Files\AutoCAD 2004\acad.exe" & Chr(34) & " /b " & Chr(34) & "import" & Chr(34) & [Forms]![AutoCAD Updater]![Tekst31]

End Function

It gives an error: runtime error 13
Types doesn't match

It is something with an integer...

TIF
Han
 
Oops,

forgot part of it:

Code:
Y=Chr(34) & "C:\Program Files\AutoCAD 2004\acad.exe" & Chr(34) & " /b " & Chr(34) & "import" & Chr(34) & [Forms]![AutoCAD Updater]![Tekst31]

And your math skills are correct!

Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top