Jump to content

Recommended Posts

Posted

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.

 

(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
[color=red](vl-load-com)[/color]

[color=red](setq vpent (car (nentsel "\nselect viewport")))   ;user selects viewport and viewport id is stored under vpent[/color]
[color=red](vlax-ename->vla-object vpent)    ;vpent is transformed from an entity to a VLA object[/color]
[color=red](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.[/color]


(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.

Desired_titlemark_result.jpg

Lisp_error.PNG

Posted

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.

(setq vpent (vlax-ename->vla-object vpent))

Posted

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

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

:thumbsup: .......

Posted
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.

(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. :)

Posted
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 .

 

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

Posted

To select only viewports you can go with the following .

 

(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?

Posted

Is the scale a property of the vport if so then can you not use a vla get scale ? will check

Posted
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 .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...