Author Topic: Runs yet it doesn't  (Read 3631 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Runs yet it doesn't
« on: February 21, 2013, 11:38:22 AM »
If I manually load each line of code from VLisp, it works.  But if I load the whole routine, and call from command line in Autocad, it fails.  Any ideas?



(defun c:foo (/LayerFrozen)
  (vl-load-com)
  (setq
    acadObject     (vlax-get-acad-object)
    acadActiveDoc (vla-get-ActiveDocument acadObject)
  )
  (setq acadLayers (vla-get-Layers acadActiveDoc))
  (vlax-for eachLayer acadLayers
    (if
      (= (vla-get-Freeze eachLayer) :vlax-true)
    (vla-put-Freeze eachLayer :vlax-false)
    )
  )
)
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Runs yet it doesn't
« Reply #1 on: February 21, 2013, 11:40:38 AM »
manually load each line  :-P

without running that code my hint would be: branch the logic when the layer being processed is the current layer
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

fixo

  • Guest
Re: Runs yet it doesn't
« Reply #2 on: February 21, 2013, 11:42:53 AM »
Try to wrap your logic in 'vl-catch-all-apply' function

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Runs yet it doesn't
« Reply #3 on: February 21, 2013, 11:44:19 AM »
sledge hammers, how do they work?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Runs yet it doesn't
« Reply #4 on: February 21, 2013, 11:44:42 AM »
MP - since Im not trying to freeze current layer would it matter?
FIXO - I haven't learned how to do that yet
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Runs yet it doesn't
« Reply #5 on: February 21, 2013, 11:46:29 AM »
OK, but why?  I know that seems open-ended, but reading a property shouldn't make it fail
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Runs yet it doesn't
« Reply #6 on: February 21, 2013, 11:48:09 AM »
This:
Code: [Select]
(defun c:foo (/LayerFrozen)needs to be:
Code: [Select]
(defun c:foo (/ LayerFrozen)else the '/LayerFrozen' symbol is interpreted as a parameter.

[ Well, strictly it should be ]:
Code: [Select]
(defun c:foo (/ acadObject acadActiveDoc acadLayers)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Runs yet it doesn't
« Reply #7 on: February 21, 2013, 11:50:20 AM »
Lee, that was it.  Stupid space
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Runs yet it doesn't
« Reply #8 on: February 21, 2013, 11:51:50 AM »
Lee, that was it.  Stupid space

No worries  :-)

FWIW, I would suggest:
Code: [Select]
(defun c:foo ( )
    (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (= :vlax-true (vla-get-freeze layer))
            (vla-put-freeze layer :vlax-false)
        )
    )
    (princ)
)

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Runs yet it doesn't
« Reply #9 on: February 21, 2013, 11:53:26 AM »
I get bitten by that from time to time as well, mostly when I hurry.  I put it in the same category as typing ".8" instead of "0.8".  Seems small but carries *really* big teeth.   :wink:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Runs yet it doesn't
« Reply #10 on: February 21, 2013, 11:53:58 AM »
Lee, I see what you did, but for clarity I am explicitly setting up vars so I can follow along.  I'm finally trying to learn VLisp
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Runs yet it doesn't
« Reply #11 on: February 21, 2013, 11:57:22 AM »
Good eye Lee.

Having said that, observe:

Code: [Select]
(vla-put-freeze
    (vla-item
        (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (getvar "clayer")
    )           
    :vlax-false
)

; error: Automation Error. Invalid layer
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

fixo

  • Guest
Re: Runs yet it doesn't
« Reply #12 on: February 21, 2013, 12:14:54 PM »

FIXO - I haven't learned how to do that yet
See if this will works
Code: [Select]
(setq adoc (vla-get-activedocument
              (vlax-get-acad-object))
      aclayers (vla-get-layers adoc))
       ;;thaw
      (vlax-for olayer aclayers
(vl-catch-all-apply 'vla-put-freeze
  (list olayer :vlax-false)))
        ;;freeze
      (vlax-for olayer aclayers
(vl-catch-all-apply 'vla-put-freeze
  (list olayer :vlax-true)))

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Runs yet it doesn't
« Reply #13 on: February 21, 2013, 12:28:04 PM »
Lee, I see what you did, but for clarity I am explicitly setting up vars so I can follow along.  I'm finally trying to learn VLisp

No problem!
I tend to only assign variables if I intend to reference the object more than once in the code - but if it helps you learn the object model hierarchy, I won't object  :-P

Good eye Lee.

Cheers dude  8-)

Having said that, observe...

Thanks, I considered that - however, for this case, since the current layer will never be frozen, it's freeze property will not be modified by the code.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Runs yet it doesn't
« Reply #14 on: February 21, 2013, 01:17:15 PM »
... however, for this case, since the current layer will never be frozen, it's freeze property will not be modified by the code.

True, good point. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst