Author Topic: Xattach within a Script  (Read 6811 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Xattach within a Script
« on: December 07, 2015, 02:41:30 PM »
I am trying to get xattach to work within a script file. If I use the standard command in the script it does not prompt for a dialog box. I was able to find a simple lisp that would allow me to select multiple xref dwgs at one time.

Code: [Select]
(defun c:xattach4script ()
 (initdia)
 (command "_xattach")
 );end defun

And the Script file that I placed it in

Code: [Select]
(load xattach4script)
xattach4script

Below is the error I get. (I have no idea about this one.)
Quote
Command: _SCRIPT
Enter script file name <C:\Users\Documents\Drawing1.scr>: "C:\Users\Desktop\xa.SCR"
Command: (load xattach4script)
; error: bad argument type: stringp nil
Command: xattach4script
nil
Path to DWG file to attach: *Cancel*

Again, If I load the lisp normally and not though the script, it works like it is suppose too.

Thanks guys!
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xattach within a Script
« Reply #1 on: December 08, 2015, 03:20:28 AM »
The (load) function requires a string argument.

tedg

  • Swamp Rat
  • Posts: 811
Re: Xattach within a Script
« Reply #2 on: December 08, 2015, 02:33:12 PM »
Something like..
Code: [Select]
(load "c:\\yourpath\\xattach4sccript.lsp")


?
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Xattach within a Script
« Reply #3 on: December 08, 2015, 02:38:16 PM »
Ok I have gotten to load up properly but its now saying on the command prompt:

Path to DWG file to attach:

Again, before just running XATTACH I get a popup dialog box. Weird.
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xattach within a Script
« Reply #4 on: December 08, 2015, 02:46:10 PM »
No, that is not weird. When called from the context of a script dialogs should be suppressed.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Xattach within a Script
« Reply #5 on: December 08, 2015, 02:47:37 PM »
Ok. It is doing what it is supposed to be doing. Then, any idea how I can get "that command" to work within a script?
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xattach within a Script
« Reply #6 on: December 08, 2015, 02:57:51 PM »
Try using the -XREF command instead.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xattach within a Script
« Reply #7 on: December 08, 2015, 03:02:45 PM »
BTW: The big question is: Why do you create a script in the first place?

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Xattach within a Script
« Reply #8 on: December 08, 2015, 03:05:10 PM »
I did have this all in a macro. ran great (I thought) then a recommendation of a script would be easier to use. I said, I can try.
Civil3D 2020

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Re: Xattach within a Script
« Reply #9 on: December 08, 2015, 03:11:42 PM »
Code - Auto/Visual Lisp: [Select]
  1. (command "_xattach" "~")
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xattach within a Script
« Reply #10 on: December 08, 2015, 03:16:41 PM »
Only if I need to change multiple dwgs would I choose a script. And even then I would use the script only to open the dwgs, start a Lisp and then close the dwgs. I can't think of a situation where a script is 'easier'.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Xattach within a Script
« Reply #11 on: December 08, 2015, 03:26:24 PM »
The workflow was to start a new drawing, insert all these layers, set dim styles and text styles, page setups, then a lisp at the end to save as.
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Xattach within a Script
« Reply #12 on: December 08, 2015, 05:40:50 PM »
Only if I need to change multiple dwgs would I choose a script. And even then I would use the script only to open the dwgs, start a Lisp and then close the dwgs. I can't think of a situation where a script is 'easier'.

Agreed.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Xattach within a Script
« Reply #13 on: December 11, 2015, 04:14:48 PM »
I am going to assume that the script is necessary for some reason, so I would take one of two approaches:
Code: [Select]
(defun xattach4script (fName /)
 (initdia)
 (command "_xattach" fName)
 );end defun

And then call it from the script as:
Code: [Select]
(xattach4script <<Add full file path here, but make sure that all \ are replaced with \\>>)

Alternatively, you could just call xattach directly from the script:
Code: [Select]
filedia
0
_xAttach
<<Filename>>

If you want the dialog box to appear, then just the _XAttach line would be applicable.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Re: Xattach within a Script
« Reply #14 on: December 11, 2015, 08:34:39 PM »
The tilde option I suggested doesn't work any longer (it used to)?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Xattach within a Script
« Reply #15 on: December 14, 2015, 04:45:19 PM »
The tilde option I suggested doesn't work any longer (it used to)?
Strange, the help file says it still does, so I am asking for technical support on this, as I would find it useful as well.
« Last Edit: December 14, 2015, 04:51:06 PM by cmwade77 »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Xattach within a Script
« Reply #16 on: December 16, 2015, 07:12:32 PM »
And now that I have contacted Autodesk and they were unable to reproduce the error, the ~ is working again.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Xattach within a Script
« Reply #17 on: December 16, 2015, 08:59:29 PM »
Awesome. Thank you for digging in in that.
Civil3D 2020