Author Topic: Attribute - field replacement routine  (Read 2470 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Attribute - field replacement routine
« on: January 27, 2011, 02:11:17 PM »
Using Acad2010 and XP PRO, I'm trying to create a routine to replace a standard attribute value ( for the drawing file name) with field expression.
Quote

(COMMAND "-ATTEDIT" "N" "N" "2010DWGATTRIBUTES" "DRWG._NO." "*" "*" "%<\AcVar Filename \f "%tc1%fn2">%")

I'm sure it's the quotes in the final expression that are the problem.
I've tried a variation of this in a script file....still no go.

Any ideas would be greatly appreciated.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Attribute - field replacement routine
« Reply #1 on: January 27, 2011, 02:14:00 PM »
You might be better of doing this in LISP, then perhaps calling the LISP from the Script.

These will help in that respect:

http://lee-mac.com/attributefunctions.html

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Attribute - field replacement routine
« Reply #2 on: January 27, 2011, 02:19:24 PM »
Example calling function:

Code: [Select]
(defun c:test ( / ss i ) (vl-load-com)

  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "2010DWGATTRIBUTES") (66 . 1))))

    (repeat (setq i (sslength ss))
      (LM:SetAttributeValue (vlax-ename->vla-object (ssname ss (setq i (1- i)))) "DRWG._NO."
        "%<\\AcVar Filename \\f \"%tc1%fn2\">%"
      )
    )
  )
  (princ)
)

Uses my Visual LISP 'LM:SetAttributeValue' sub from the link I provided.

[ Untested ]

airportman

  • Newt
  • Posts: 37
  • i customize when required
Re: Attribute - field replacement routine
« Reply #3 on: September 12, 2012, 04:00:26 PM »
Lee:

what if its a diesel expression. will this work?
Perception is a state of mind  -/ Twitter = @hochanz -/ Intel i7 - 3.07GHz -/ 12GB Ram -/ Nvidia Quadro FX 1800

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Attribute - field replacement routine
« Reply #4 on: September 12, 2012, 04:10:49 PM »
what if its a diesel expression. will this work?

Yes, but you will need to use the Field code generated for the DIESEL expression, not the DIESEL expression on it's own (unless RTEXT is used of course). Note also that the naming convention for my set of Attribute functions has been updated since this thread was last active.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Attribute - field replacement routine
« Reply #5 on: September 13, 2012, 06:15:00 AM »
Just as a help, seeing as the old OP post mentioned problems with the quotes. It's not a simple copy-paste procedure. E.g. after you've created the Diesel expression in the Field dialog manually, you select and copy the contents of the Field expression (bottom of dialog).

But note there're always some backslashes in that expression (and sometimes there's also double-quotes). These have to be escaped when using inside a lisp-string, by prefixing each with a backslash. This can be tedious for a long expression, not to mention missing one is a very real possibility.

For that reason I generally let AutoLisp handle all these escapes for me. Type the following into the ACad command line:
Code: [Select]
(getstring t)Or add that into a defun c: command of your own and use the command itself.

Then paste the expression you've copied into the getstring prompt and press Enter. It will then show a fully escaped version in the command palette / text screen. This you can then select and copy-paste directly into your code.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.