PDA

View Full Version : Bad argument type issue



tntdraftsol
2014-01-09, 03:41 PM
Greetings all!

Here is what I got. I wrote a routine that used a dialog box to populate our company title mark with a title, mark number and scale. Once I got this routine to work I thought I would add some additional functionality and have the user pick the viewport the title mark would be associated with and by using a field have the scale populate based on the viewport, not user input. The final result I am after is attached.

Here is my code, the portion in red is where I think my problem is, but I am not sure:


(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

and the error I am getting is also attached. If anyone could help shine some light on this for me I would appriciate it. This is my second LISP assignment and I am enjoying the learning expierence, but this one has stumped me. Thank you all for reading.

Tharwat
2014-01-09, 07:55 PM
Hi ,

You did convert the selected entity to Vla-object without assigning it to a variable while you used the variable vpent to get the object ID with is NOT Vla-object .

Anyway to have it solved , you can reassign the same variable name you used with the entity to be for the Vla-object .

e,g.



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


Good luck .

tntdraftsol
2014-01-09, 08:50 PM
Hi ,

You did convert the selected entity to Vla-object without assigning it to a variable while you used the variable vpent to get the object ID with is NOT Vla-object .

Anyway to have it solved , you can reassign the same variable name you used with the entity to be for the Vla-object .

e,g.



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


Good luck .

Thank you for your reply, but I'm afraid I don't understand your post. Please forgive my misunderstanding, but could you explain that again?

Tharwat
2014-01-09, 09:13 PM
Thank you for your reply, but I'm afraid I don't understand your post. Please forgive my misunderstanding, but could you explain that again?

You assigned the selected entity to to variable vpent as below which is right :





(setq vpent (car (nentsel "\nselect viewport")))



Then you converted the entity to VLA-Object ... but you did not assign this conversion to any variable so the variable vpent still holds the selected entity and not the VLA-Object .





(vlax-ename->vla-object vpent)



So as shown on the following line you need a VLA-Object to continue , but it won't because as I have mentioned earlier that the variable vpent hold entity and not VLA-Object ;)





(vl-princ-to-string(vla-get-Objectid vpent))




Modify your codes and run the routine then let me know . :)

tntdraftsol
2014-01-10, 02:34 PM
You assigned the selected entity to to variable vpent as below which is right :



Then you converted the entity to VLA-Object ... but you did not assign this conversion to any variable so the variable vpent still holds the selected entity and not the VLA-Object .



So as shown on the following line you need a VLA-Object to continue , but it won't because as I have mentioned earlier that the variable vpent hold entity and not VLA-Object ;)




Modify your codes and run the routine then let me know . :)


Now I got it! I understand what you mean now. I did as you suggested and I am getting the block to insert with the scale as a field, BUT instead of displaying the scale as expected it is displaying "####" (see attached). I looked at the field expression for the viewport with my routine and then looked at another field expression for the same viewport but not with my routine and the object IDs do NOT match (see attached). why would the object ID be different for the same viewport? Is the fact that I am transforming the entity into a VLA oject chaninging the ID?

Here is the revised portion of code:


(setq vpent (car (nentsel "\nselect viewport"))) ;user selects viewport and viewport id is stored under vpent

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


Thanks again! I'm closer, but not there yet.:?

Tharwat
2014-01-10, 03:38 PM
Are you working on 64 Operating System ?

tntdraftsol
2014-01-10, 03:52 PM
Are you working on 64 Operating System ?

yes, we have Civil 3D 2012 on Windows 7, 64 bit.

Tharwat
2014-01-10, 04:06 PM
yes, we have Civil 3D 2012 on Windows 7, 64 bit.

Okay , so use this function by gile to get the ObjectID .



(defun gc:GetObjectIdString (obj)
;;; By Gile
(or *util*
(setq *util* (vla-get-Utility
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
)
(if (vlax-method-applicable-p *util* 'GetObjectIdString)
(vla-GetObjectIdString *util* obj :vlax-false)
(itoa (vla-get-ObjectId obj))
)
)


Then you need to combine it as the following .



(setq scale_fld (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
(gc:GetObjectIdString vpent)
">%).CustomScale \\f \"%sn\">%"
)
)


Hope this helps :)

tntdraftsol
2014-01-10, 04:52 PM
Okay , so use this function by gile to get the ObjectID .



(defun gc:GetObjectIdString (obj)
;;; By Gile
(or *util*
(setq *util* (vla-get-Utility
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
)
(if (vlax-method-applicable-p *util* 'GetObjectIdString)
(vla-GetObjectIdString *util* obj :vlax-false)
(itoa (vla-get-ObjectId obj))
)
)


Then you need to combine it as the following .



(setq scale_fld (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
(gc:GetObjectIdString vpent)
">%).CustomScale \\f \"%sn\">%"
)
)


Hope this helps :)

Awesome! Thank you so very much Tharwat and thank you Gile! it works! I would have never come up with that function. the block comes in exactly how it should for rectangular viewports, now i'll have to see about figuring out how to get it to work with polygonal viewports. Again thank you. cheers! :beer:


Update: I found that if you clip a rectangular viewport after inserting the block the scale field will still continue to function properly. so that could be a workaround.

Tharwat
2014-01-10, 04:57 PM
Awesome! Thank you so very much Tharwat and thank you Gile! it works! I would have never come up with that function. the block comes in exactly how it should for rectangular viewports, now i'll have to see about figuring out how to get it to work with polygonal viewports. Again thank you. cheers! :beer:

Excellent , You're welcome anytime .

Tharwat
2014-01-10, 05:07 PM
Update: I found that if you clip a rectangular viewport after inserting the block the scale field will still continue to function properly. so that could be a workaround.

So do you still have any doubts about the codes ?

tntdraftsol
2014-01-10, 05:20 PM
Another update: I figured out that when the viewport is polygonal before running the routine and the user selects said polygonal viewport the object that is read for the field expression is the polyline associated with the viewport, not the viewport itself. So that is why on polygonal viewports the scale field will display "####".

So I have a couple of options, I could continue to tweak my code with some kind of if/then to account for differing viewports, or leave as is and have the user hover over the polygonal viewport and before they select it have them hit the spacebar first, so they would select the viewport instead of the polyline. I'll have to think about that one.

tntdraftsol
2014-01-10, 05:23 PM
So do you still have any doubts about the codes ?

No, not at all. what you suggested works perfectly. I will just need to decide, or actually my CAD Manager will need to decide if I will need to account for different viewports in the code, or let the user know they will need to use the spacebar before selecting the viewport so that they actually select the viewport and not the polyline.

Tharwat
2014-01-10, 06:11 PM
Another update: I figured out that when the viewport is polygonal before running the routine and the user selects said polygonal viewport the object that is read for the field expression is the polyline associated with the viewport, not the viewport itself. So that is why on polygonal viewports the scale field will display "####".


Unfortunately that is correct and the Polygonal that represented as a viewport is not considered as a viewport so it still considered as a polyline :|

Thanks for the supports , it is highly appreciated .