getlocalemedianames ... driving me insane ... please help !!!

Discussion in 'AutoCAD' started by Andrew McDonald, Jan 19, 2004.

  1. I have the routine below which enables me to do One-click plotting.
    I need to retrieve the available paper sizes from the device
    \\GCSERVER\Cadjet 2
    which I can do by using :

    (DEFUN getlocalemedianames (adoc / la cmn lmn)
    (SETQ la (VLA-ITEM (VLA-GET-LAYOUTS adoc) "Model"))
    (FOREACH cmn (getcanonicalmedianames adoc)
    (SETQ lmn (CONS (VLA-GETLOCALEMEDIANAME la cmn) lmn))
    )
    (REVERSE lmn)
    )
    (getlocalemedianames (vla-get-activedocument (vlax-get-acad-object)))

    I then copy the required media name "ISO A1 594 x 840 mm." into the code
    below
    but it refuses to recognize this value. I've tried eliminating spaces,
    taking out the period
    etc. I'm going freaking mad.
    What am I doing & why can't I pass this name into the script ?

    Regards
    Andrew McDonald


    ;; Routine for '1 click' plotting of titleblock sheets.
    ;; The routine asks the user to pick a titleblock or crop mark
    ;; of the titlesheet. The routine retrieves certain values to establish
    ;; the sheet size and then process that information in the background
    ;; and sends the plot to the specified device.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VARIABLES DEFINITIONS
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; blk = block (title block or border) to plot from
    ;; bn = block name
    ;; bxs = blocks x scale factor (discontinued)
    ;; bip = block insertion point


    ;; This routine has now taken away the option of having a titleblock
    inserted at a scale other than 1,
    ;; (previously used when titleblocks were inserted in model space and
    scaled)
    ;; the bxs variable will now be set at 1.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ERROR HANDLING ROUTINE
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    (defun myerror (s) ; If an error (such as CTRL-C) occurs
    while this command is active...
    (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
    )
    (setvar "filedia" 1)
    (setvar "cmdecho" 1)
    (setq *error* olderr) ; Restore old *error* handler
    (princ)
    )

    ;;**************************************************************************
    *************************
    ;;
    ;; Routine to plot to full size.

    (defun c:autoplotfull (/ ifd icm icd blk bn bip)
    (setq olderr *error* *error* myerror)
    (setq ifd (getvar "filedia"))
    (setvar "filedia" 0)(princ)
    (setq icm (getvar "cmdecho"))
    (setvar "cmdecho" 0)(princ)
    (setq ilu (getvar "luprec"))
    (setvar "luprec" 0)(princ)
    (prompt "\nAutoPLOT routine for TVS Partnership ... loaded ")(princ)
    (prompt "\nSelect TITLE BLOCK or CROP MARK of what you wish to plot
    ")(princ)
    (setq blk (entget (car (entsel)))) ;retrieve block definition
    (setq bn (cdr (assoc 2 blk))) ;retrieve blocks name
    (setq bip (cdr (assoc 10 blk))) ;retrieve blocks insertion point
    (if bn
    (cond
    ((= bn "a1 portrait") (PLOT_A1)) ;if A1 PORTRAIT then do PLOT_A1
    ((= bn "a1 landscape") (PLOT_A1)) ;if A1 LANDSCAPE then do
    PLOT_A1
    (setq bn nil)
    )
    )
    )
    (princ)



    ;;;;;;;;;;;;;;;;;;;; ROUTINE TO SAVE VIEW "A1" & PLOT THE SELECTED TITLE
    BLOCK/BORDER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    (defun PLOT_A1 (/ PS)

    (if (tblsearch "view" "a1") (command "view" "d" "a1"))
    (command "view" "w" "a1" bip (list 810.0 565.5)) ;creates a
    new view "A1" to plot
    (command "view" "r" "a1")

    ? ?
    (command "-PLOT" "y" "" "\\\\GCSERVER\\Cadjet 2" "ISO A1 594 x 840 mm."
    "m" "l" "n" "v" "a1" "1=1" "c" "y" "tvs.ctb" "y" "n" "n" "n" "n" "y" "y")

    ; Detailed plot configuration? [Yes/No] <No>: y
    ; Enter a layout name or [?] <Floor Plan Layout>:
    ; Enter an output device name or [?] <\\GCSERVER\Cadjet 2>:
    ; Enter paper size or [?] <ISO A1 594 X 840 MM>: - Actually called
    "User265" by system
    ; Enter paper units [Inches/Millimeters] <Millimeters>:
    ; Enter drawing orientation [Portrait/Landscape] <Landscape>:
    ; Plot upside down? [Yes/No] <No>:
    ; Enter plot area [Display/Extents/Limits/View/Window] <Extents>: v
    ; Enter view name <>: a1
    ; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <1:1>: 1:1
    ; Enter plot offset (x,y) or
    <Center>:
    ; Plot with plot styles? [Yes/No] <Yes>:
    ; Enter plot style table name or [?] (enter . for none) <tvs.ctb>:
    ; Plot with lineweights? [Yes/No] <Yes>:
    ; Scale lineweights with plot scale? [Yes/No] <No>:
    ; Plot paper space first? [Yes/No] <No>:
    ; Hide paperspace objects? [Yes/No] <No>:
    ; Write the plot to a file [Yes/No] <N>:
    ; Save changes to page setup [Yes/No]? <Y>
    ; Proceed with plot [Yes/No] <Y>:

    (setq blk nil)
    (setq bn nil)
    (setq bip nil)
    (setvar "filedia" ifd)(princ)
    (setvar "cmdecho" icm)(princ)
    (setvar "luprec" ilu)(princ)
    )
    (princ)​
     
    Andrew McDonald, Jan 19, 2004
    #1
  2. hmmm,
    I checked my routine for setting up pages and ran accross this code:
    note that PAPER-SIZE is the variable the user is supplying, set it to your size at the beginning

    (setq PAPER-SIZE <fill in here>)

    (SETQ AOBJ (vlax-get-acad-object)
    ADOC (vla-get-ActiveDocument AOBJ)
    ALA (vla-get-ActiveLayout ADOC)
    )
    (vla-RefreshPlotDeviceInfo ALA)
    (setq CANON-LIST (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames ALA)))
    PAPER-SIZES (mapcar '(lambda (x) (vla-GetLocaleMediaName ALA x)) CANON-LIST)
    )

    ;CHECK FOR PAPER SIZE EXISTING
    (IF (NOT (MEMBER PAPER-SIZE PAPER-SIZES))
    (PROGN
    (ALERT "Paper Size is not avalable to that plotter.\nThe following text is a list of those that are:")
    (TEXTSCR)
    (FOREACH ITEM (GET-PAPER-SZ)
    (PRINT ITEM)
    )
    (EXIT)
    )
    )

    function to get the sizes (not sure why I didnt just use the PAPER-SIZES variable for this....:
    (DEFUN GET-PAPER-SZ ( / AOBJ ADOC ALA CANON-LIST PAPER-SIZES)
    (SETQ AOBJ (vlax-get-acad-object)
    ADOC (vla-get-ActiveDocument AOBJ)
    ALA (vla-get-ActiveLayout ADOC)
    )
    (vla-RefreshPlotDeviceInfo ALA)
    (setq CANON-LIST (vlax-safearray->list (vlax-variant-value (vla-GetCanonicalMediaNames ALA)))
    PAPER-SIZES (mapcar '(lambda (x) (vla-GetLocaleMediaName ALA x)) CANON-LIST)
    )
    PAPER-SIZES
    )

    it appears there is another prop to look at...

    "Andrew McDonald" <andrew.mATtvspartnership.com.au>
    |>I have the routine below which enables me to do One-click plotting.
    |>I need to retrieve the available paper sizes from the device
    |>\\GCSERVER\Cadjet 2
    |>which I can do by using :
    |>
    |>(DEFUN getlocalemedianames (adoc / la cmn lmn)
    |> (SETQ la (VLA-ITEM (VLA-GET-LAYOUTS adoc) "Model"))
    |> (FOREACH cmn (getcanonicalmedianames adoc)
    |> (SETQ lmn (CONS (VLA-GETLOCALEMEDIANAME la cmn) lmn))
    |> )
    |> (REVERSE lmn)
    |>)
    |>(getlocalemedianames (vla-get-activedocument (vlax-get-acad-object)))
    |>
    |>I then copy the required media name "ISO A1 594 x 840 mm." into the code
    |>below
    |>but it refuses to recognize this value. I've tried eliminating spaces,
    |>taking out the period
    |>etc. I'm going freaking mad.
    |>What am I doing & why can't I pass this name into the script ?
    |>
    |>Regards
    |>Andrew McDonald
    |>
    |>
    |>;; Routine for '1 click' plotting of titleblock sheets.
    |>;; The routine asks the user to pick a titleblock or crop mark
    |>;; of the titlesheet. The routine retrieves certain values to establish
    |>;; the sheet size and then process that information in the background
    |>;; and sends the plot to the specified device.
    |>
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VARIABLES DEFINITIONS
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>;; blk = block (title block or border) to plot from
    |>;; bn = block name
    |>;; bxs = blocks x scale factor (discontinued)
    |>;; bip = block insertion point
    |>
    |>
    |>;; This routine has now taken away the option of having a titleblock
    |>inserted at a scale other than 1,
    |>;; (previously used when titleblocks were inserted in model space and
    |>scaled)
    |>;; the bxs variable will now be set at 1.
    |>
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ERROR HANDLING ROUTINE
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>
    |>(defun myerror (s) ; If an error (such as CTRL-C) occurs
    |>while this command is active...
    |> (if (/= s "Function cancelled")
    |> (princ (strcat "\nError: " s))
    |> )
    |> (setvar "filedia" 1)
    |> (setvar "cmdecho" 1)
    |> (setq *error* olderr) ; Restore old *error* handler
    |> (princ)
    |>)
    |>
    |>;;**************************************************************************
    |>*************************
    |>;;
    |>;; Routine to plot to full size.
    |>
    |>(defun c:autoplotfull (/ ifd icm icd blk bn bip)
    |> (setq olderr *error* *error* myerror)
    |> (setq ifd (getvar "filedia"))
    |> (setvar "filedia" 0)(princ)
    |> (setq icm (getvar "cmdecho"))
    |> (setvar "cmdecho" 0)(princ)
    |> (setq ilu (getvar "luprec"))
    |> (setvar "luprec" 0)(princ)
    |> (prompt "\nAutoPLOT routine for TVS Partnership ... loaded ")(princ)
    |> (prompt "\nSelect TITLE BLOCK or CROP MARK of what you wish to plot
    |>")(princ)
    |> (setq blk (entget (car (entsel)))) ;retrieve block definition
    |> (setq bn (cdr (assoc 2 blk))) ;retrieve blocks name
    |> (setq bip (cdr (assoc 10 blk))) ;retrieve blocks insertion point
    |> (if bn
    |> (cond
    |> ((= bn "a1 portrait") (PLOT_A1)) ;if A1 PORTRAIT then do PLOT_A1
    |> ((= bn "a1 landscape") (PLOT_A1)) ;if A1 LANDSCAPE then do
    |>PLOT_A1
    |> (setq bn nil)
    |> )
    |> )
    |>)
    |>(princ)
    |>
    |>
    |>
    |>;;;;;;;;;;;;;;;;;;;; ROUTINE TO SAVE VIEW "A1" & PLOT THE SELECTED TITLE
    |>BLOCK/BORDER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>
    |>(defun PLOT_A1 (/ PS)
    |>
    |> (if (tblsearch "view" "a1") (command "view" "d" "a1"))
    |> (command "view" "w" "a1" bip (list 810.0 565.5)) ;creates a
    |>new view "A1" to plot
    |> (command "view" "r" "a1")
    |>
    |>? ?
    |> (command "-PLOT" "y" "" "\\\\GCSERVER\\Cadjet 2" "ISO A1 594 x 840 mm."
    |>"m" "l" "n" "v" "a1" "1=1" "c" "y" "tvs.ctb" "y" "n" "n" "n" "n" "y" "y")
    |>
    |>; Detailed plot configuration? [Yes/No] <No>: y
    |>; Enter a layout name or [?] <Floor Plan Layout>:
    |>; Enter an output device name or [?] <\\GCSERVER\Cadjet 2>:
    |>; Enter paper size or [?] <ISO A1 594 X 840 MM>: - Actually called
    |>"User265" by system
    |>; Enter paper units [Inches/Millimeters] <Millimeters>:
    |>; Enter drawing orientation [Portrait/Landscape] <Landscape>:
    |>; Plot upside down? [Yes/No] <No>:
    |>; Enter plot area [Display/Extents/Limits/View/Window] <Extents>: v
    |>; Enter view name <>: a1
    |>; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <1:1>: 1:1
    |>; Enter plot offset (x,y) or
    <Center>:
    |>; Plot with plot styles? [Yes/No] <Yes>:
    |>; Enter plot style table name or [?] (enter . for none) <tvs.ctb>:
    |>; Plot with lineweights? [Yes/No] <Yes>:
    |>; Scale lineweights with plot scale? [Yes/No] <No>:
    |>; Plot paper space first? [Yes/No] <No>:
    |>; Hide paperspace objects? [Yes/No] <No>:
    |>; Write the plot to a file [Yes/No] <N>:
    |>; Save changes to page setup [Yes/No]? <Y>
    |>; Proceed with plot [Yes/No] <Y>:
    |>
    |> (setq blk nil)
    |> (setq bn nil)
    |> (setq bip nil)
    |> (setvar "filedia" ifd)(princ)
    |> (setvar "cmdecho" icm)(princ)
    |> (setvar "luprec" ilu)(princ)
    |>)
    |>(princ)
    |>

    James Maeding
    Civil Engineer/Programmer​
     
    James Maeding, Jan 20, 2004
    #2
  3. I should have read some more, you have similar code but mine might help.

    The way I would debug this is to of course try it by hand a bunch, like you are doing.
    Then try some other paper sizes to see if it hangs on everything or just one.
    Make sure you walk through the code with vlisp and use the inspect tool to verify all variables before the actual
    command sequence. If you are not doing this, its the difference between a black box and a (dimmly) lit room...
    Hope someone else reads and replies as this must have happened to others. Try the print-plot group too.
    thx

    "Andrew McDonald" <andrew.mATtvspartnership.com.au>
    |>I have the routine below which enables me to do One-click plotting.
    |>I need to retrieve the available paper sizes from the device
    |>\\GCSERVER\Cadjet 2
    |>which I can do by using :
    |>
    |>(DEFUN getlocalemedianames (adoc / la cmn lmn)
    |> (SETQ la (VLA-ITEM (VLA-GET-LAYOUTS adoc) "Model"))
    |> (FOREACH cmn (getcanonicalmedianames adoc)
    |> (SETQ lmn (CONS (VLA-GETLOCALEMEDIANAME la cmn) lmn))
    |> )
    |> (REVERSE lmn)
    |>)
    |>(getlocalemedianames (vla-get-activedocument (vlax-get-acad-object)))
    |>
    |>I then copy the required media name "ISO A1 594 x 840 mm." into the code
    |>below
    |>but it refuses to recognize this value. I've tried eliminating spaces,
    |>taking out the period
    |>etc. I'm going freaking mad.
    |>What am I doing & why can't I pass this name into the script ?
    |>
    |>Regards
    |>Andrew McDonald
    |>
    |>
    |>;; Routine for '1 click' plotting of titleblock sheets.
    |>;; The routine asks the user to pick a titleblock or crop mark
    |>;; of the titlesheet. The routine retrieves certain values to establish
    |>;; the sheet size and then process that information in the background
    |>;; and sends the plot to the specified device.
    |>
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VARIABLES DEFINITIONS
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>;; blk = block (title block or border) to plot from
    |>;; bn = block name
    |>;; bxs = blocks x scale factor (discontinued)
    |>;; bip = block insertion point
    |>
    |>
    |>;; This routine has now taken away the option of having a titleblock
    |>inserted at a scale other than 1,
    |>;; (previously used when titleblocks were inserted in model space and
    |>scaled)
    |>;; the bxs variable will now be set at 1.
    |>
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ERROR HANDLING ROUTINE
    |>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>
    |>(defun myerror (s) ; If an error (such as CTRL-C) occurs
    |>while this command is active...
    |> (if (/= s "Function cancelled")
    |> (princ (strcat "\nError: " s))
    |> )
    |> (setvar "filedia" 1)
    |> (setvar "cmdecho" 1)
    |> (setq *error* olderr) ; Restore old *error* handler
    |> (princ)
    |>)
    |>
    |>;;**************************************************************************
    |>*************************
    |>;;
    |>;; Routine to plot to full size.
    |>
    |>(defun c:autoplotfull (/ ifd icm icd blk bn bip)
    |> (setq olderr *error* *error* myerror)
    |> (setq ifd (getvar "filedia"))
    |> (setvar "filedia" 0)(princ)
    |> (setq icm (getvar "cmdecho"))
    |> (setvar "cmdecho" 0)(princ)
    |> (setq ilu (getvar "luprec"))
    |> (setvar "luprec" 0)(princ)
    |> (prompt "\nAutoPLOT routine for TVS Partnership ... loaded ")(princ)
    |> (prompt "\nSelect TITLE BLOCK or CROP MARK of what you wish to plot
    |>")(princ)
    |> (setq blk (entget (car (entsel)))) ;retrieve block definition
    |> (setq bn (cdr (assoc 2 blk))) ;retrieve blocks name
    |> (setq bip (cdr (assoc 10 blk))) ;retrieve blocks insertion point
    |> (if bn
    |> (cond
    |> ((= bn "a1 portrait") (PLOT_A1)) ;if A1 PORTRAIT then do PLOT_A1
    |> ((= bn "a1 landscape") (PLOT_A1)) ;if A1 LANDSCAPE then do
    |>PLOT_A1
    |> (setq bn nil)
    |> )
    |> )
    |>)
    |>(princ)
    |>
    |>
    |>
    |>;;;;;;;;;;;;;;;;;;;; ROUTINE TO SAVE VIEW "A1" & PLOT THE SELECTED TITLE
    |>BLOCK/BORDER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    |>
    |>(defun PLOT_A1 (/ PS)
    |>
    |> (if (tblsearch "view" "a1") (command "view" "d" "a1"))
    |> (command "view" "w" "a1" bip (list 810.0 565.5)) ;creates a
    |>new view "A1" to plot
    |> (command "view" "r" "a1")
    |>
    |>? ?
    |> (command "-PLOT" "y" "" "\\\\GCSERVER\\Cadjet 2" "ISO A1 594 x 840 mm."
    |>"m" "l" "n" "v" "a1" "1=1" "c" "y" "tvs.ctb" "y" "n" "n" "n" "n" "y" "y")
    |>
    |>; Detailed plot configuration? [Yes/No] <No>: y
    |>; Enter a layout name or [?] <Floor Plan Layout>:
    |>; Enter an output device name or [?] <\\GCSERVER\Cadjet 2>:
    |>; Enter paper size or [?] <ISO A1 594 X 840 MM>: - Actually called
    |>"User265" by system
    |>; Enter paper units [Inches/Millimeters] <Millimeters>:
    |>; Enter drawing orientation [Portrait/Landscape] <Landscape>:
    |>; Plot upside down? [Yes/No] <No>:
    |>; Enter plot area [Display/Extents/Limits/View/Window] <Extents>: v
    |>; Enter view name <>: a1
    |>; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <1:1>: 1:1
    |>; Enter plot offset (x,y) or
    <Center>:
    |>; Plot with plot styles? [Yes/No] <Yes>:
    |>; Enter plot style table name or [?] (enter . for none) <tvs.ctb>:
    |>; Plot with lineweights? [Yes/No] <Yes>:
    |>; Scale lineweights with plot scale? [Yes/No] <No>:
    |>; Plot paper space first? [Yes/No] <No>:
    |>; Hide paperspace objects? [Yes/No] <No>:
    |>; Write the plot to a file [Yes/No] <N>:
    |>; Save changes to page setup [Yes/No]? <Y>
    |>; Proceed with plot [Yes/No] <Y>:
    |>
    |> (setq blk nil)
    |> (setq bn nil)
    |> (setq bip nil)
    |> (setvar "filedia" ifd)(princ)
    |> (setvar "cmdecho" icm)(princ)
    |> (setvar "luprec" ilu)(princ)
    |>)
    |>(princ)
    |>

    James Maeding
    Civil Engineer/Programmer​
     
    James Maeding, Jan 20, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.