vla-put-color

Discussion in 'AutoCAD' started by Jamie Duncan \(remove lock to reply\), Apr 14, 2004.

  1. So here goes - I know nothing...
    I have an existing layer, I want to reset it's color, linetype and noplot
    status.

    So let's see:

    before I do anything I need (vl-load-com)

    can I just do this once at startup?

    (setq acadobject (vlax-get-Acad-Object))

    now I'm in the acad object model. when do I have to do this? every time I
    want to work on objects? or just once in the drawing session


    then I have to say I'm working on the activedoc right?

    (setq activedocument (vla-get-activedocument acadobject))

    and now I need to collect all the layers right?

    (setq LayerTable (vla-get-layers activedocument))



    now if I want a specific layer I need to
    (setq thelayer (vla-item LayerTable "layername")

    and say (setq ltype1 "DASHED")

    (vla-put-linetype thelayer ltype1)

    is this right

    and val-put-color theLayer resets the color

    and the plotting thing?

    am I clueless or what...


    --


    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan \(remove lock to reply\), Apr 14, 2004
    #1
  2. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    Hi Jamie,
    This is a good start. To answer the multiple "do I do this once", Yes.
    I've placed all of mine in a seperate lisp file that I have set to
    load/run in my acaddoc.lsp.
    Such as :
    (defun miffs_base_utils ()
    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    *doc* (vla-get-activedocument *acad*)
    *utils* (vla-get-utility *doc*))
    )
    (miffs_base_utils)

    Then *acad*, *doc*, and *utils* are available to all of my routines.

    See below for other responses.....

    Sort of CORRECT! You don't need the linetype name in a variable, unless
    you need it for other things.....such as making sure it is loaded prior
    to trying to use it. If it isn't already loaded this will fail.
    (vla-put-color theLayer color); color must be an integer, changed for >
    R2002 I think
    (vla-put-plottable theLayer :vlax-true) ; or :vlax-false
    not really. it looks like you've been following these posts pretty
    well....


    HTH,
    Jeff
     
    Jeff Mishler, Apr 14, 2004
    #2
  3. Here's the function (I have thos commands of yours executed at startup of
    each drawing - is this right?)


    (defun jddreadlayernames (filename filepathname / lin pos1 pos2 lname1
    lntype1 lcr1 end1 LayerTable theLayer aNewLayer flagc flagl)
    (setq lin (read-line filepathname)
    LayerTable (vla-get-layers activedocument)
    )
    (prompt (strcat "\nAdding new layers, colors and linetypes from " filename
    " ...\n"))
    (while (and lin (/= lin ""))
    (setq pos1 (vl-string-position (ascii ",") lin)
    pos2 (vl-string-position (ascii ",") lin (+ pos1 2))
    lname1 (substr lin 1 pos1)
    lcr1 (substr lin (+ pos1 2) (- pos2 pos1 1))
    lntype1 (substr lin (+ pos2 2))
    flagc T
    flagl T
    lcr1 (if (= (atoi lcr1) 0)(progn (setq flagc nil) 1 )(atoi lcr1))
    )
    (if (not (tblsearch "ltype" lntype1))(setq lntype1 "CONTINUOUS" flagl
    nil))
    (if (not (< 0 lcr1 257))(setq lcr1 1 flagc nil))
    (setq end1 (tblsearch "layer" lname1))
    (if end1
    (progn
    (setq thelayer (vla-item LayerTable lname1))
    (if flagl (vla-put-linetype thelayer lntype1))
    (if flagc (vla-put-color theLayer lcr1))
    )
    (progn
    (setq aNewLayer (vla-add LayerTable lname1))
    (vla-put-linetype aNewLayerr lntype1))
    (vla-put-color aNewLayer lcr1))
    )
    )
    (setq lin (read-line filepathname))
    )
    (command ".layer" "plot" "n" "*NP*" "")
    (close filepathname)
    )

    can you see wherte I'm going wrong here?

    Thanks

    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan \(remove lock to reply\), Apr 14, 2004
    #3
  4. okay - I made a few booboos, fixed them and still no luck

    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    *doc* (vla-get-activedocument *acad*)
    *utils* (vla-get-utility *doc*))
    )
    ;;;starup stuff

    (defun jddreadlayernames (filename filepathname / lin pos1 pos2 lname1
    lntype1 lcr1 end1 LayerTable theLayer aNewLayer flagc flagl)
    (setq lin (read-line filepathname)
    LayerTable (vla-get-layers *doc*)
    )
    (prompt (strcat "\nAdding new layers, colors and linetypes from " filename
    " ...\n"))
    (while (and lin (/= lin ""))
    (setq pos1 (vl-string-position (ascii ",") lin)
    pos2 (vl-string-position (ascii ",") lin (+ pos1 2))
    lname1 (substr lin 1 pos1)
    lcr1 (substr lin (+ pos1 2) (- pos2 pos1 1))
    lntype1 (substr lin (+ pos2 2))
    flagc T
    flagl T
    lcr1 (if (= (atoi lcr1) 0)(progn (setq flagc nil) 1 )(atoi lcr1))
    )
    (if (not (tblsearch "ltype" lntype1))(setq lntype1 "CONTINUOUS" flagl
    nil))
    (if (not (< 0 lcr1 257))(setq lcr1 1 flagc nil))
    (setq end1 (tblsearch "layer" lname1))
    (if end1
    (progn
    (setq thelayer (vla-item LayerTable lname1))
    (if flagl (vla-put-linetype thelayer lntype1))
    (if flagc (vla-put-color theLayer lcr1))
    )
    (progn
    (setq aNewLayer (vla-add LayerTable lname1))
    (vla-put-linetype aNewLayerr lntype1)
    (vla-put-color aNewLayer lcr1)
    )
    )
    (setq lin (read-line filepathname))
    )
    (command ".layer" "plot" "n" "*NP*" "")
    (close filepathname)
    )

    --


    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan \(remove lock to reply\), Apr 14, 2004
    #4
  5. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    I don't see where you are opening the file for reading. Is it opened in
    the function that calls this?

    I don't see anything else that is glaringly wrong. How is it not
    working? error?

    Also, you really don't need to use the tblsearch to see if the layer
    exists.
    (setq theLayer (vla-add LayerTable lname1))
    This will add the layer if it doesn't exist and just set "theLayer" to
    the existing one if it does.
    This is true of Text Styles, too.
    In place of the (command "layer" "p" ....) near the end, I'd place a
    check in the while loop to do this:
    (if (wcmatch lname1 "*NP*")
    (vla-set-ploattable theLayer :vlax-false)
    (vla-set-ploattable theLayer :vlax-true)
    )

    HTH,
    Jeff
     
    Jeff Mishler, Apr 14, 2004
    #5
  6. Thanks for all your help. No error or nothing - just doesn't work. It's
    part of a larger routine (which works fine) Everything was working until I
    decided to vla it. Now I'm on R2000 - is this a problem?


    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan \(remove lock to reply\), Apr 14, 2004
    #6
  7. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    Could you post the code that calls this routine as well as a few sample
    line from the layer file?

    Jeff
     
    Jeff Mishler, Apr 14, 2004
    #7
  8. The routine was fine with entmake and command ".layer" etc. I've attached
    the whole thing after my sig, and portions of the typical layer file (comma
    delimited)


    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.

    (defun c:arctlaysin (/ ans filena fn ocmd temp temp2)
    ;;;(arctvsav) sav vars - sets up error and sets cmdecho to 0
    (setvar "expert" 3)
    (while (/= ans "N")
    (setq temp (getstring "\nLinetype file to load <ACAD>: ")
    ltfile (if (= temp "") "ACAD" temp)
    temp (findfile (strcat ltfile ".lin"))
    )
    (if temp
    (progn
    (command "linetype" "l" "*" ltfile "")
    (setq ans "N")
    )
    (prompt (strcat "\nLinetype file <" ltfile "> not found - try
    again."))
    ) )
    (setq filena "sheet")
    (if (null (setq fn (open (strcat ARCTDRVE "/archr/" filena ".lay") "r")))
    (progn
    (setq temp nil)
    (prompt (strcat "\nFile "(strcase filena)" not found - try
    again."))
    )
    )
    (jddreadlayernames filena fn)
    (setq temp nil)
    (prompt (strcat "\nLayer Config. files will be loaded from the < "
    ARCTDRVE "/archr > subdirectory. "));;; arctdrve setup at startup
    (while (null temp)
    (initget "Floorplan Detail Siteplan Elevation")
    (setq temp2 (getkword "\nSelect Layers to Load:
    Floorplan/Siteplan/Detail/Elevation/Old <Floorplan>:"))
    (cond
    ((= temp2 "Floorplan")(setq filena "flrlayer" temp "y"))
    ((= temp2 "Siteplan")(setq filena "site" temp "y"))
    ((= temp2 "Detail")(setq filena "detail" temp "y"))
    ((= temp2 "Elevation")(setq filena "elev" temp "y"))
    ((= temp2 nil)(setq filena "flrlayer" temp "y"))
    ((= temp2 "Old")(setq filena "flrlayerold" temp "y"))
    )
    (if (null (setq fn (open (strcat ARCTDRVE "/archr/" filena
    ".lay") "r")))
    (progn
    (setq temp nil)
    (prompt (strcat "\nFile "(strcase filena)" not found - try
    again."))
    )
    )
    )
    (jddreadlayernames filena fn)
    (prompt "\nImporting of Layer Configuration for this drawing now
    complete.")
    (setvar "cmdecho" ocmd) ; restore variable
    (setq c:arctlaysin nil)
    (arctvrst)
    (princ)
    )

    (princ)
    (defun jddreadlayernames (filename filepathname / lin pos1 pos2 lname1
    lntype1 lcr1 end1 LayerTable theLayer aNewLayer flagc flagl)
    (setq lin (read-line filepathname)
    LayerTable (vla-get-layers *doc*)
    )
    (prompt (strcat "\nAdding new layers, colors and linetypes from " filename
    " ...\n"))
    (while (and lin (/= lin ""))
    (setq pos1 (vl-string-position (ascii ",") lin)
    pos2 (vl-string-position (ascii ",") lin (+ pos1 2))
    lname1 (substr lin 1 pos1)
    lcr1 (substr lin (+ pos1 2) (- pos2 pos1 1))
    lntype1 (substr lin (+ pos2 2))
    flagc T
    flagl T
    lcr1 (if (= (atoi lcr1) 0)(progn (setq flagc nil) 1 )(atoi lcr1))
    )
    (if (not (tblsearch "ltype" lntype1))(setq lntype1 "CONTINUOUS" flagl
    nil))
    (if (not (< 0 lcr1 257))(setq lcr1 1 flagc nil))
    (setq end1 (tblsearch "layer" lname1))
    (if end1
    (progn
    (setq thelayer (vla-item LayerTable lname1))
    (if flagl (vla-put-linetype thelayer lntype1))
    (if flagc (vla-put-color theLayer lcr1))
    )
    (progn
    (setq aNewLayer (vla-add LayerTable lname1))
    (vla-put-linetype aNewLayerr lntype1)
    (vla-put-color aNewLayer lcr1)
    )
    )
    (setq lin (read-line filepathname))
    )
    (command ".layer" "plot" "n" "*NP*" "")
    (close filepathname)
    )
     
    Jamie Duncan \(remove lock to reply\), Apr 14, 2004
    #8
  9. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    Jamie,
    I just ran your routine after making some minor revisions...added the
    variable ARCTDRVE since my startup won't have set this, rem'ed out the
    most everything after the first call to the sub, fixed one mis-spelled
    var in the sub, renamed the file you sent to "sheet.lay"... and it ran
    just fine.

    Try loading/running this in the VLIDE and set a breakpoint. Open the
    watch window and make sure at least the *LAST-VALUE* is shown. After it
    stops at the breakpoint step through the routine using the F8 key. Keep
    on eye on the watch window to see what is happening with each line.

    I don't think that using 2000 will make any difference, I'm on 2002 and
    they are essentially the same as far as lisp & activex go.

    Good luck,
    Jeff
     
    Jeff Mishler, Apr 14, 2004
    #9
  10. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    I should've mentioned that the mis-spelled var, if left as it was did
    generate an error. So i'm not sure if you are actually opening the files
    to read. By using the method in my last post you can verify whether you
    are or aren't.

    The line that needs changing is: (vla-put-linetype aNewLayerr lntype1)
    It has 1 too many r's........

    Jeff
     
    Jeff Mishler, Apr 14, 2004
    #10
  11. Jamie Duncan \(remove lock to reply\)

    Jamie Duncan Guest

    that's it! Hah, it's always the dumb things that catch you!

    Thanks ever so much for your help Jeff,



    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 15, 2004
    #11
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.