+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Location
    Jefferson City, MO
    Posts
    7

    Unhappy bad argument issue with fields and viewports

    Registered forum members do not see this ad.

    Greetings all!

    I recently wrote a routine that took information from the user via a dialog box and populated our titlemark block. After I got this working I wanted to add some additional functionality by having the user pick the viewport the titlemark would be associated with and by using a field populate the scale in the titlemark instead of having the user type in the input. I have attached my desired result.

    here is the code I am using, I think my problem area is in red.

    Code:
    (defun C:TLMK ( / TLMK_LEN PT1)
      (setvar "CMDECHO" 0)
      (setq tempunits (getvar "insunits"))
    ;======================================================================================================================================== LOADS DIALOG BOX
    (defun TLMK(/ DCL_ID)
     (setq DCL_ID (load_dialog "n:/tuterj/AutoLISP/Working/TL-MK_Scale_add.DCL"))
     (if (not (new_dialog "TLMK" DCL_ID)) (exit))
     (setq mark_n nil)
     (setq title_n nil)
     
     (action_tile "cancel" "(done_dialog) (exit)")
     (action_tile "mark_n" "(setq mark_n $value)")
     (action_tile "title_n" "(setq title_n $value)")
     
     (start_dialog)
     (unload_dialog DCL_ID)
     (princ)
    ) ;defun TLMK
     (TLMK)
    ;======================================================================================================================================== End of Dialog BOx
    (vl-load-com)
     
    (setq vpent (car (nentsel "\nselect viewport")))   ;user selects viewport and viewport id is stored under vpent
    (vlax-ename->vla-object vpent)    ;vpent is transformed from an entity to a VLA object
    (setq scale_fld (strcat "%<\AcObjProp.16.2 Object(%<\_ObjId "(vl-princ-to-string(vla-get-Objectid vpent))">%).CustomScale \f\"%sn\">%"))  ;assigns field expression to variable.
     
     
    (setq PT1 (getpoint "\nselect insertion point: "))
    (setvar "ATTDIA" 0)
    (setq title_u (strcase title_n))   ;declaring additional variable to change case for title_n
    (setvar "insunits" 0)  ;setting insertion units to unitless for proper scale of inserted block
     
    (command "insert" "N:/Tuterj/AutoLISP/Working/TitleMark-field.dwg" PT1 "" "" title_u scale_fld mark_n)  ;inserting the contents of TitleMark drawing and inserting user input from dialog box.
     
    (setvar "ATTDIA" 1)
    (setvar "CMDECHO" 1)
    (setvar "insunits" tempunits)
    ) ;defun C:TLMK
    I have also attached the error I am getting when I try to run the routine. I would appriciate any help anyone is willing to provide. Thank you all for your time and for reading.
    Attached Images

  2. #2
    Senior Member cwake's Avatar
    Discipline
    Civil
    cwake's Discipline Details
    Occupation
    Civil Designer
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    Jun 2011
    Location
    Queensland Australia
    Posts
    133

    Default

    The problem lies in the fact that the return value from converting the ename to VLA object reference is not being stored. So when you supply the variable "vpent" as an argument to vla-get-Objectid, it is still referencing an ename not an object which errors.

    The simplest fix would be to reuse "vpent" to store the object reference before supplying it to vla-get-Objectid.
    Code:
    (setq vpent (vlax-ename->vla-object vpent))

  3. #3
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,049

  4. #4
    Senior Member cwake's Avatar
    Discipline
    Civil
    cwake's Discipline Details
    Occupation
    Civil Designer
    Discipline
    Civil
    Using
    AutoCAD 2015
    Join Date
    Jun 2011
    Location
    Queensland Australia
    Posts
    133

    Default

    Ahhh. I was wondering why nobody had answered even though several days had passed since the original post. That explains it.

  5. #5
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,049

    Default

    Quote Originally Posted by cwake View Post
    Ahhh. I was wondering why nobody had answered even though several days had passed since the original post. That explains it.
    .......

  6. #6
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Location
    Jefferson City, MO
    Posts
    7

    Smile

    Quote Originally Posted by cwake View Post
    The problem lies in the fact that the return value from converting the ename to VLA object reference is not being stored. So when you supply the variable "vpent" as an argument to vla-get-Objectid, it is still referencing an ename not an object which errors.

    The simplest fix would be to reuse "vpent" to store the object reference before supplying it to vla-get-Objectid.
    Code:
    (setq vpent (vlax-ename->vla-object vpent))
    Cwake, thank you for your reply! As you saw Tharwat gave me some suggestions on the AUGI forum. Thank you again for your time in responding.

  7. #7
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,049

    Default

    Quote Originally Posted by bobafett View Post
    As you saw Tharwat gave me some suggestions on the AUGI forum. Thank you again for your time in responding.
    Hi ,

    If you still searching for to be able to select diagonal Polyline which represent viewports , I would say as far as I know that you can not get the scale of that entity since that it considered as a polyline and not a viewport unless someone else approves the contrary .

    To select only viewports you can go with the following .

    Code:
    (setq ss (ssget '((0 . "VIEWPORT"))))

  8. #8
    Forum Newbie
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Location
    Jefferson City, MO
    Posts
    7

    Default

    Quote Originally Posted by Tharwat View Post
    To select only viewports you can go with the following .

    Code:
    (setq ss (ssget '((0 . "VIEWPORT"))))
    Tharwat, Thank you for your reply. Another person from the Swamp forum gave me a function that allows you to select polygonal viewports and it works. Lee Mace also suggested what you put in your previous post, but I am unsure as to where it should go in the code. Where would the ss variable be referenced later in the program?

  9. #9
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,723

    Default

    Is the scale a property of the vport if so then can you not use a vla get scale ? will check
    A man who never made mistakes never made anything

  10. #10
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,049

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by bobafett View Post
    Where would the ss variable be referenced later in the program?
    It is just a variable name and you can change it to fit your needs , and I just gave you an example .

Similar Threads

  1. Intersecting Viewports Issue
    By jaredmccullough in forum AutoCAD General
    Replies: 21
    Last Post: 16th Aug 2012, 08:25 pm
  2. Need Help to keep my data with an argument
    By Michaels in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 27th Feb 2011, 02:26 pm
  3. How to save a value which has given to an argument ?
    By Sweety in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 30th Nov 2010, 06:58 pm
  4. Fields & Viewports
    By woodman78 in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 3rd Jun 2010, 04:02 pm
  5. Bad argument
    By MarlaE in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 18th Jan 2008, 11:56 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts