Author Topic: ActiveX for getting multiple layers  (Read 4935 times)

0 Members and 1 Guest are viewing this topic.

OcCad

  • Guest
ActiveX for getting multiple layers
« on: February 27, 2008, 07:30:22 PM »
How can I grab multiple layers in ActiveX such as...

(command "-layer" "freeze" "layer*" "")

do i use this somehow (setq lyrs (vla-get-item (vla-get-layers Doc) ?)?

so then i can             (vla-put-freeze lyrs :vlax-true)

and has someone figured a way around (vla-get-activelayer) for odbx
« Last Edit: February 27, 2008, 08:21:36 PM by Lexicon »

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: ActiveX for getting multiple layers
« Reply #1 on: February 27, 2008, 08:55:53 PM »
In ActiveX you just loop through the Layers collection, check the name using wildcards, and set each one that matches the criteria to freeze, using (vl-catch-all-apply) to trap for the expected error of "can't freeze current layer". ODBX cannot set (or get) the ActiveLayer since nothing is active.......leaving for the night and no PC at home tonight to verify this, but I'm pretty sure this is the case.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #2 on: February 27, 2008, 09:16:09 PM »
ODBX cannot set (or get) the ActiveLayer since nothing is active ...

Correct.

Here's an "Available Properties" table (generated from AutoCAD 2008). Certainly suggests what is inheriting / implementing what OO wise; i.e. IAcadDatabase smells like a base class / interface.

PropertyIAcadDocument    IAxDbDocument    IAcadDatabase
Active         *         -         -
ActiveDimStyle         *         -         -
ActiveLayer         *         -         -
ActiveLayout         *         -         -
ActiveLinetype         *         -         -
ActiveMaterial         *         -         -
ActivePViewport         *         -         -
ActiveSelectionSet         *         -         -
ActiveSpace         *         -         -
ActiveTextStyle         *         -         -
ActiveUCS         *         -         -
ActiveViewport         *         -         -
Application         *         ~         -
Blocks         *         *         *
Database         *         *         -
Dictionaries         *         *         *
DimStyles         *         *         *
ElevationModelSpace         *         *         *
ElevationPaperSpace         *         *         *
FileDependencies         *         *         *
FullName         *         -         -
Groups         *         *         *
HWND         *         -         -
Height         *         -         -
Layers         *         *         *
Layouts         *         *         *
Limits         *         *         *
Linetypes         *         *         *
MSpace         *         -         -
Materials         *         *         *
ModelSpace         *         *         *
Name         *         *         -
ObjectSnapMode         *         -         -
PaperSpace         *         *         *
Path         *         -         -
PickfirstSelectionSet         *         -         -
Plot         *         -         -
PlotConfigurations         *         *         *
Preferences         *         *         *
ReadOnly         *         -         -
RegisteredApplications         *         *         *
Saved         *         -         -
SectionManager         *         *         *
SelectionSets         *         -         -
SummaryInfo         *         *         *
TextStyles         *         *         *
UserCoordinateSystems         *         *         *
Utility         *         -         -
Viewports         *         *         *
Views         *         *         *
Width         *         -         -
WindowState         *         -         -
WindowTitle         *         -         -

Note: The Application property is available for IAxDbDocuments but if you request its value it will throw an error (trappable).

:)
« Last Edit: February 27, 2008, 11:14:30 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: ActiveX for getting multiple layers
« Reply #3 on: February 28, 2008, 02:56:02 AM »
Hi,
   
Wonderful.

Where are you find this table ?

@+

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #4 on: February 28, 2008, 06:18:25 AM »
Hi,
   
Wonderful.

Where are you find this table ?

@+

Sorry, I'm married.

I made it.

What does @+ mean?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: ActiveX for getting multiple layers
« Reply #5 on: February 28, 2008, 07:28:09 AM »
Quote
Sorry, I'm married.
I don't understand, I said a mistake ?

Quote
What does @+ mean?
In france at the next

For the table, thank you for your work

@+

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #6 on: February 28, 2008, 07:35:59 AM »
Quote
Sorry, I'm married.
I don't understand, I said a mistake ?

It was a joke. "Hi wonderful" is akin to "Hi darling", "'Ow you doin'" ^-^ etc; you know, one of Mav's pickup lines.

Quote
What does @+ mean?
In france at the next

Ok.

For the table, thank you for your work

You're most welcome Patrick.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Patrick_35

  • Guest
Re: ActiveX for getting multiple layers
« Reply #7 on: February 28, 2008, 07:55:38 AM »
Ah, OK
Sorry for the misunderstanding,
So I wanted to say hello and then say it's great  :roll:

I'm also married

@+

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #8 on: February 28, 2008, 08:01:31 AM »
No misunderstanding Patrick ... I chose to exploit what I thought a comedic opportunity, though in hindsight, didn't work as planned (no great guffaws). C'est la vie; ma vie.

Rewind: Thank you for kindnesses and my pleasure.

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

Patrick_35

  • Guest
Re: ActiveX for getting multiple layers
« Reply #9 on: February 28, 2008, 08:42:49 AM »
Humour is difficult with a foreign language, especially when there is a lack of practice.
But it will work for next time  :lol:

@+

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #10 on: February 28, 2008, 09:02:04 AM »
There are many that don't think I'm funny in English; it was delusional to think I could be in French.

:ugly:

Medic: Can I get a bowl of ibuprofen and some freakin' coffee over here? Jeesh.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

OcCad

  • Guest
Re: ActiveX for getting multiple layers
« Reply #11 on: February 28, 2008, 09:00:31 PM »
MP,

How would I go about error trapping in odbx "key not found?" i've tried peter jamtgaards errortrap function:

Code: [Select]
(defun error_trap (symFunction / objError result)
 (if (vl-catch-all-error-p
      (setq objError (vl-catch-all-apply
                     '(lambda (X)(set X (eval symFunction)))
                      (list 'result))))
  (progn
   (print (vl-catch-all-error-message objError))
   (print symfunction) 
   nil)
  (if result result 'T)))

as well as others that i have found online however none seem to work. "key not found" is refering to a layer I would like to freeze and trying condition/if statements arent doing me any good either.

Here is a snipit of the code where I'm getting an error:

Code: [Select]
(if (setq rev_layer (vla-item (vla-get-layers dbx_doc) rev_cloud))
  (progn
    (vla-put-freeze rev_layer :vlax-false)
    (vla-SaveAs dbx_doc dwg_path)
  )progn
);if

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ActiveX for getting multiple layers
« Reply #12 on: February 28, 2008, 09:18:00 PM »
...............
Here is a snipit of the code where I'm getting an error:

Code: [Select]
(if (setq rev_layer (vla-item (vla-get-layers dbx_doc) rev_cloud))
  (progn
    (vla-put-freeze rev_layer :vlax-false)
    (vla-SaveAs dbx_doc dwg_path)
  )progn
);if

What is the value of  rev_cloud ??
Other than that, you may have to post all the code and the drawing as well.

Have you tried debugging in the VLIDE ? .. with BreakOnError set  or perhaps with animation on ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

OcCad

  • Guest
Re: ActiveX for getting multiple layers
« Reply #13 on: February 28, 2008, 09:21:34 PM »
rev_cloud is just the layer name in my drawing

  ex: (setq rev_cloud "s-anno-revc-1")

the error occurs because the layer is not in the dbx_doc. I just haven't been able to figure out how to error trap for it.
And by error trap i mean

-if layer does not exist
-do nothing and close out of dbx_doc

used conditionals and if/then's with no success.
« Last Edit: February 28, 2008, 09:52:23 PM by Lexicon »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ActiveX for getting multiple layers
« Reply #14 on: February 28, 2008, 10:53:19 PM »
A very simple vl-catch-all-apply wrapper around a vla-item call is all it takes:

Code: [Select]
(defun [color=red]_GetItem[/color] ( collection key / item )

    [color=green];;  caller's responsibility to pass
    ;;  a legitimate collection and key[/color]

    (vl-catch-all-apply
       '(lambda ( )
            (setq item
                (vla-item collection key)
            )
        )
    )

    item

)

However, I'm a little reluctant to post post it without a precaution. It assumes
the programmer fully understands the ramifications of the sledge error trapping
it encapsulates, because it can hide logic errors in your code if used improperly.

For example, if one passed it an invalid collection object you'd never know it,
because the _GetItem would blithely return nil, which suggests the key doesn't
exist, which in fact would be misleading. This would be a logic error, i.e. the program
is coded incorrectly (failed to pass a valid collection object), as opposed to a run
time error (specified key doesn't in a valid collection), so please use carefully.

Hope this abbreviated explanation made sense.

Anyway, an example of use using the variables you provided previously might be ...

Code: [Select]
[color=green];;  assumes variables dbx_doc, rev_cloud are properly set ...[/color]

(if (setq rev_layer ([color=red]_GetItem[/color] (vla-get-layers dbx_doc) rev_cloud))
    ([color=purple]Do_Stuff_With_Layer_object[/color] rev_layer)
)

Of course, what you do with the layer object via ObjectDBX has to be legit ...

... for what it's worth, cheers.

:)
« Last Edit: February 28, 2008, 10:56:43 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst