VLA-OBJECT nil

VLA-OBJECT nil

Anonymous
適用対象外
9,643件の閲覧回数
7件の返信
メッセージ1/8

VLA-OBJECT nil

Anonymous
適用対象外

Hello All,

I'm pretty new to VLA but it seems like a powerful tool in autolisp so I'm trying to learn.

The LISP I've been working on is meant to give a dimension from centreline (origin point) to the user selected point, and then through VLA it changes various properties of the dimension. Sometimes it works flawlessly and for seemingly no reason, other times it gives me the "error: bad argument type: VLA-OBJECT nil".

Could anyone shed some light on why this sometimes works and sometimes doesn't?

 

(defun C:OCL ()
                (setq pt1 
                                (getpoint "\nChoose a Point : ")
                )
                (setq pt2
                                (trans '(0 0 0) 0 1)
                )
                (setq x1
                                (car pt1)
                )
                (setq y1
                                (cadr pt1)
                )
                (setq z1
                                (caddr pt1)
                )
                (setq x
                                (car pt2)
                )
                (setq y
                                (cadr pt2)
                ) 
                (setq z 
                                (caddr pt2)
                )

                (setq li0
                                (list x y1 z1)
                )
                (command "DIMLINEAR" pt1 li0 pause)
                (command "_CHPROP" "LAST" "" "A" "YES" "")
                (command "SELECT" "LAST" "")
                (vl-load-com)
                (vlax-for oDim
                                (setq ss  
                                                (vla-get-activeselectionset *activeDoc*)
                                )
                                (vla-put-textoverride oDim "<> OCL")
                                (vla-put-HorizontalTextPosition oDim acFirstExtensionLine)
                                (vla-put-Arrowhead2Type oDim acArrowNone)
                                (vla-put-ExtLine2Suppress oDim :vlax-true)
                                (vla-put-DimLine2Suppress oDim :vlax-true)
                                (vla-put-ArrowheadSize oDim 2.5)
                                (vla-put-ExtensionLineExtend oDim 1.5)
                                (vla-put-ExtensionLineOffset oDim 2.5)
                                (vla-put-TextHeight oDim 2.5)
                                (vla-put-textgap oDim 0.8)
                )
                (princ)
)

Also,

Is there a way to change 'Annotative Scale' on a dimension through VLA or LISP?

Cheers,

Tyler

0 件のいいね
解決済み
9,644件の閲覧回数
7件の返信
返信 (7)
メッセージ2/8

Ranjit_Singh
Advisor
Advisor
解決済み

You have the global variable *activedoc* which if not available can cause the error sometimes. Maybe redefine the variable in the code

................
............ (setq *activedoc* (vla-get-activedocument (vlax-get-acad-object)))..
......

If the code still faisl it could be that it cannot retrieve the activeselectionset? Try setting the oDim object right after after creating the dimension

(setq oDim (vlax-ename->vla-object (entlast)))

You don't need a selectionset since you are dealing with only one entity.

 

For changing annotative scale, look into -objectscale command.

0 件のいいね
メッセージ3/8

rkmcswain
Mentor
Mentor
You only need the (vl-load-com) once per session. There is no need to execute it over and over. Having said that, it's not going to hurt anything.

The error you mention simply means that a function is not being supplied a valid VLA-Object as an argument.

Are you editing this in the VLIDE? If so, you can trace the error when it happens and it will be fairly clear.
R.K. McSwain     | CADpanacea | on twitter
0 件のいいね
メッセージ4/8

Kent1Cooper
Consultant
Consultant

Not positive, but I don't think

 

  (command "SELECT" "LAST" "")

 

leaves that selection "active."  What happens if you replace that with:

 

  (sssetfirst nil (ssget "L"))

 

which will leave it selected/highlighted/gripped, and therefore I hope what it would consider "active"?

 

 

Kent Cooper, AIA
0 件のいいね
メッセージ5/8

Anonymous
適用対象外

Hi Ranjit,

Thanks for the speedy response.

How would I go about redefining a global variable through the code (I have very limited coding experience)?

I think you're correct in this line causing the error. It doesnt seem to have issues getting the active selection set, it works properly in some dwg files, and not in others.

Thanks!

0 件のいいね
メッセージ6/8

Anonymous
適用対象外

Hi McSwain,

I haven't even heard of VLIDE, but i will most definitely check it out! all of my editing right now is done in notepad. probably a very poor decision.

Thanks,

Tyler

0 件のいいね
メッセージ7/8

Ranjit_Singh
Advisor
Advisor

I thought I already specified it, but here it is again in your code

(defun c:ocl  ()
 (setq pt1 (getpoint "\nChoose a Point : "))
 (setq pt2 (trans '(0 0 0) 0 1))
 (setq x1 (car pt1))
 (setq y1 (cadr pt1))
 (setq z1 (caddr pt1))
 (setq x (car pt2))
 (setq y (cadr pt2))
 (setq z (caddr pt2))
 (setq li0 (list x y1 z1))
 (command "DIMLINEAR" pt1 li0 pause)
 (command "_CHPROP" "LAST" "" "A" "YES" "")
 (command "SELECT" "LAST" "")
 (vl-load-com)
 (vlax-for odim  (setq ss (vla-get-activeselectionset (setq *activedoc* (vla-get-activedocument (vlax-get-acad-object)))))
  (vla-put-textoverride odim "<> OCL")
  (vla-put-horizontaltextposition odim acfirstextensionline)
  (vla-put-arrowhead2type odim acarrownone)
  (vla-put-extline2suppress odim :vlax-true)
  (vla-put-dimline2suppress odim :vlax-true)
  (vla-put-arrowheadsize odim 2.5)
  (vla-put-extensionlineextend odim 1.5)
  (vla-put-extensionlineoffset odim 2.5)
  (vla-put-textheight odim 2.5)
  (vla-put-textgap odim 0.8))
 (princ))
0 件のいいね
メッセージ8/8

Anonymous
適用対象外

Thank you so much Ranjit! The combination of redefining the *activedoc* variable, as well setting the odim and not using the selection set seems to have sorted out the issue.

Cheers.

0 件のいいね