Author Topic: Strcat a Feild is crashing with too many arguments.  (Read 2834 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Strcat a Feild is crashing with too many arguments.
« on: January 28, 2011, 02:04:40 PM »
What the heck!  Fields in code kick my but every time.

By trial & error, this feild is giving me "too many arguments" at the command line.
Code: [Select]
(setq Field1
   (strcat
     "%<\\AcObjProp Object(%<\\_ObjId "
     (itoa (vla-get-Objectid (vlax-ename->vla-object ent1)))
     ">%).Measurement \\f \"%lu4\">%"
   )
)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Strcat a Feild is crashing with too many arguments.
« Reply #1 on: January 28, 2011, 02:16:00 PM »
I'm gonna guess you need double quotes around %lu4\

""%lu4\""
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Strcat a Feild is crashing with too many arguments.
« Reply #2 on: January 28, 2011, 02:22:16 PM »
I'm gonna guess you need double quotes around %lu4\

""%lu4\""
That crashed to as well.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Strcat a Feild is crashing with too many arguments.
« Reply #3 on: January 28, 2011, 02:26:24 PM »
Worked fine for me in Acad 2010. Is ent1 an ename for a dimension?

**Edit**
Your original code worked fine for me.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Strcat a Feild is crashing with too many arguments.
« Reply #4 on: January 28, 2011, 02:30:22 PM »
The initial string works fine for me as well.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Strcat a Feild is crashing with too many arguments.
« Reply #5 on: January 28, 2011, 02:39:32 PM »
Worked fine for me in Acad 2010. Is ent1 an ename for a dimension?

**Edit**
Your original code worked fine for me.
If I try to load that partial load that sting it crashes.

Yes it is for a dimension and I am running Acad 2010 ACA.

More code below.  Everything around it works with fine when I comment out the FIELD 1 and FIELD 2. When I un-comment it crashes. :x

Quote
(if (and (setq
        ent1
         (car
      (entsel "\nSelect Width Dimension for Window Opening: ")
         )
      )
      (eq "DIMENSION" (cdr (assoc 0 (entget ent1))))
      (setq ent2
        (car
          (entsel "\nSelect Height Dimension for Window Opening:: ")
        )
      )
      (eq "DIMENSION" (cdr (assoc 0 (entget ent2))))
      )


    (setq Field1
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent1)))
        ">%).Measurement \\f \""%lu4\"">%"
      )
    )

    (setq Field2
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent2)))
        ">%).Measurement \\f \"%lu4\">%"
      )
    )

  (setq suffW "%%PW x")         
  (setq suffH "%%PH")         
   
    (setq TextStr
      (strcat
      Field1
        suffW
      Field2
        suffH
      )
    )
  )
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Strcat a Feild is crashing with too many arguments.
« Reply #6 on: January 28, 2011, 02:50:47 PM »
Code: [Select]
(if
 (and
  (setq ent1 (car (entsel "\nSelect Width Dimension for Window Opening: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent1))))
  (setq ent2 (car (entsel "\nSelect Height Dimension for Window Opening:: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent2))))
 )
    (setq Field1
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent1)))
        ">%).Measurement \\f \"%lu4\">%"
      )
     Field2
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent2)))
        ">%).Measurement \\f \"%lu4\">%"
      )
    suffW "%%PW x"        
    suffH "%%PH"      
    TextStr
      (strcat
      Field1
        suffW
      Field2
        suffH
      )
    )
)

Your original code was passing too many arguments to the if statement.

**Edit**
You could even do it without the if statement.
Code: [Select]
(and
  (setq ent1 (car (entsel "\nSelect Width Dimension for Window Opening: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent1))))
  (setq ent2 (car (entsel "\nSelect Height Dimension for Window Opening:: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent2))))
  (setq Field1
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent1)))
        ">%).Measurement \\f \"%lu4\">%"
      )
     Field2
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent2)))
        ">%).Measurement \\f \"%lu4\">%"
      )
    suffW "%%PW x"        
    suffH "%%PH"      
    TextStr
      (strcat
      Field1
        suffW
      Field2
        suffH
      )
    )
)
« Last Edit: January 28, 2011, 02:59:18 PM by jvillarreal »

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Strcat a Feild is crashing with too many arguments.
« Reply #7 on: January 28, 2011, 03:09:12 PM »

Your original code was passing too many arguments to the if statement.

Could highlight where I was doing that.  Because I can not see where.  Thanks.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Strcat a Feild is crashing with too many arguments.
« Reply #8 on: January 28, 2011, 03:12:50 PM »
Quote
Could highlight where I was doing that.  Because I can not see where.  Thanks.
This is your code formatted a little differently for clarity.
Code: [Select]
(if
 (and
  (setq ent1 (car (entsel "\nSelect Width Dimension for Window Opening: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent1))))
  (setq ent2 (car (entsel "\nSelect Height Dimension for Window Opening:: ")))
  (eq "DIMENSION" (cdr (assoc 0 (entget ent2))))
 )
 (setq Field1
      (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent1)))
        [color=red]">%).Measurement \\f \""%lu4\"">%"[/color]      );Don't need the double quotes here either
  )

  (setq Field2
    (strcat
        "%<\\AcObjProp Object(%<\\_ObjId "
        (itoa (vla-get-Objectid (vlax-ename->vla-object ent2)))
        ">%).Measurement \\f \"%lu4\">%"
    )
  )

  (setq suffW "%%PW x")        
  (setq suffH "%%PH")        
  (setq TextStr (strcat Field1 suffW Field2 suffH))

)

(If (and ...)
    (setq...)
    (setq...)
    (setq...)
    etc.
)
« Last Edit: January 28, 2011, 03:18:30 PM by jvillarreal »

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Strcat a Feild is crashing with too many arguments.
« Reply #9 on: January 28, 2011, 04:20:37 PM »
Thanks jvillarreal  and the rest of you guys.  Beers on me.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

jvillarreal

  • Bull Frog
  • Posts: 332
Re: Strcat a Feild is crashing with too many arguments.
« Reply #10 on: January 28, 2011, 04:43:42 PM »
No problem. Beers on you?! Sweet!
Make mine a
[creepy old man whisper]
Dos Equis.
[/creepy old man whisper]
 :lol:

VVA

  • Newt
  • Posts: 166
Re: Strcat a Feild is crashing with too many arguments.
« Reply #11 on: February 01, 2011, 02:09:17 AM »
To avoid any future problems with 64 bit architecture is recommended using Get-ObjectID-x86-x64 to determine ObjectID

Code: [Select]
;;------------------------------------------------ --------
;; function gets a string representation of ObjectID
;, regardless of AutoCAD x86 or x64
;; Source: "Field and objectid problem"
;; http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Field-and-objectid-problem/m-p/2478592/highlight/true#M276818
;; http://forum.dwg.ru/showthread.php?t=51822
;;------------------------------------------------ --------
(defun Get-ObjectID-x86-x64 (obj / util)
   (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
   (if (= (type obj) 'ENAME) (setq obj (vlax-ename-> vla-object obj)))
   (if (= (type obj) 'VLA-OBJECT)
      (if (> (vl-string-search "x64" (getvar "platform")) 0)
        (vlax-invoke-method util "GetObjectIdString" obj: vlax-False)
        (rtos (vla-get-objectid obj) 2 0)
      )
   )
)


Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Strcat a Feild is crashing with too many arguments.
« Reply #12 on: February 01, 2011, 11:18:32 AM »
To avoid any future problems with 64 bit architecture is recommended using Get-ObjectID-x86-x64 to determine ObjectID

Code: [Select]
;;------------------------------------------------ --------
;; function gets a string representation of ObjectID
;, regardless of AutoCAD x86 or x64
;; Source: "Field and objectid problem"
;; http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Field-and-objectid-problem/m-p/2478592/highlight/true#M276818
;; http://forum.dwg.ru/showthread.php?t=51822
;;------------------------------------------------ --------
(defun Get-ObjectID-x86-x64 (obj / util)
   (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
   (if (= (type obj) 'ENAME) (setq obj (vlax-ename-> vla-object obj)))
   (if (= (type obj) 'VLA-OBJECT)
      (if (> (vl-string-search "x64" (getvar "platform")) 0)
        (vlax-invoke-method util "GetObjectIdString" obj: vlax-False)
        (rtos (vla-get-objectid obj) 2 0)
      )
   )
)

I am sorry but this is above my head, but I would I fit this into my code and use.  And Yes I am using a 64bit machine.  We just upgraded my a lot of my users to 64bit and we use fields a good bit.  Thanks for the heads up.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans