Author Topic: How to get plot style names from STB file?  (Read 13709 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
How to get plot style names from STB file?
« on: May 04, 2012, 11:21:23 AM »
Is it possible to get the plot style names from an STB file? The only thing I can come up with is an ugly workaround using the the logfile and the -Layer command. Is there a better way?


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #2 on: May 05, 2012, 06:44:19 PM »
Thank you Lee for those links.

Well, this is turning out to be quite a --==={challenge}===-- for me.

First I had quite some trouble finding a Zlib dll that would register with regsvr32.exe. But I was able to register this one:
http://www.dogma.net/markn/ZlibOCX2.dll
It is mentioned on http://www.zlib.net/ as "unsupported VB5 binary".
This dll reads and writes files.

Second problem: reading the binary file, removing the first 60 bytes, and then writing the result to a new binary file that the dll can then decompress. I have checked out code from Lee Mac and MP. See below.
Lee's read function produces a variant of the type 8209(?). But MP's code will only read the first portion of the stb file. So I am using Lee's (LM:ReadBinaryStream) function for reading.
As I am not able to recreate a variant of the type 8209 I am not able to use Lee's code for writing. So I am using MP's (_WriteStream). But somehow the conversion to text that his write function requires causes trouble. In my test only 290 bytes instead of 440 - 60 = 380 bytes were written.

Basically I am stuck here. Any and all insights are welcome!

My code:
Code: [Select]
(setq data (vlax-safearray->list (vlax-variant-value (LM:ReadBinaryStream "default.stb" 0)))) ; List of integers. Length 440 (equals 440 bytes).
(setq txt (substr (vl-list->string data) 61))                                                 ; Chop off first 60.
(_WriteStream (strcat (getvar 'dwgprefix) "default_Minus_60_Bytes.stb") txt "w")              ; Write as text. Only 290 bytes are written?

(setq zlibIF (vlax-create-object "zlibIF.zlibIF.1"))
(vlax-put zlibIF 'inputfilename (strcat (getvar 'dwgprefix) "MANUAL_default_Minus_60_Bytes.stb"))
(vlax-put zlibIF 'outputfilename (strcat (getvar 'dwgprefix) "MANUAL_default_Minus_60_Bytes.txt"))
(vlax-invoke zlibIF 'decompress)
(if zlibIF (vlax-release-object zlibIF))

Lee Mac's code:
http://www.cadtutor.net/forum/archive/index.php/t-57294.html?s=5868f10b6c04f0c55def20c8e85e764e
Code: [Select]
;;-----------------=={ Read Binary Stream }==-----------------;;
;; ;;
;; Uses the ADO Stream Object to read a supplied file and ;;
;; returns a variant of bytes. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; filename - filename of file to read. ;;
;; len - number of bytes to read ;;
;; (if non-numerical, less than 1, or greater than the size ;;
;; of the file, everything is returned). ;;
;;------------------------------------------------------------;;
;; Returns: ;;
;; Variant of Binary data which may be converted to a list ;;
;; bytes using the relevant VL Variant functions or used ;;
;; with LM:WriteBinaryStream. ;;
;;------------------------------------------------------------;;
(defun LM:ReadBinaryStream ( filename len / ADOStream result )
  (vl-load-com)
  (setq result
    (vl-catch-all-apply
      (function
        (lambda ( / size )
          (setq ADOStream (vlax-create-object "ADODB.Stream"))
          (vlax-invoke ADOStream 'Open)
          (vlax-put-property ADOStream 'type 1)
          (vlax-invoke-method ADOStream 'loadfromfile filename)
          (vlax-put-property ADOStream 'position 0)
          (setq size (vlax-get ADOStream 'size))
          (vlax-invoke-method ADOStream 'read (if (and (numberp len) (< 0 len size)) (fix len) -1))
        )
      )
    )
  )
  (if ADOStream (vlax-release-object ADOStream))
  (if (not (vl-catch-all-error-p result))
    result
  )
)

;;-----------------=={ Write Binary Stream }==----------------;;
;; ;;
;; Uses the ADO Stream Object to write a variant of bytes to ;;
;; a specified file. File is created if non-existent or ;;
;; overwritten if found. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; filename - filename of file to read. ;;
;; data - variant of binary data to write to the file. ;;
;; (as returned by LM:ReadBinaryStream) ;;
;;------------------------------------------------------------;;
;; Returns: Filename of specified file, else nil. ;;
;;------------------------------------------------------------;;
(defun LM:WriteBinaryStream ( filename data / ADOStream result )
  (vl-load-com)
  (setq result
    (vl-catch-all-apply
      (function
        (lambda ( )
          (setq ADOStream (vlax-create-object "ADODB.Stream"))
          (vlax-put-property ADOStream 'type 1)
          (vlax-invoke ADOStream 'open)
          (vlax-invoke-method ADOStream 'write data)
          (vlax-invoke ADOStream 'savetofile filename 2)
        )
      )
    )
  )
  (if ADOStream (vlax-release-object ADOStream))
  (if (not (vl-catch-all-error-p result))
    file
  )
)

MP's code:
http://www.theswamp.org/index.php?topic=17465.0
Code: [Select]
(defun _ReadStream ( path len / fso file stream result )

    ;;  If the file is successful read the data is returned as
    ;;  a string. Won't be tripped up by nulls, control chars
    ;;  including ctrl z (eof marker). Pretty fast (feel free
    ;;  to bench mark / compare to alternates).
    ;;
    ;;  If the caller wants the result as a list of byte values
    ;;  simply use vl-string->list on the result:
    ;;
    ;;      (setq bytes
    ;;          (if (setq stream (_ReadStream path len))
    ;;              (vl-string->list stream)
    ;;          )
    ;;      )           
    ;;
    ;;  Arguments:
    ;;
    ;;      path  <duh>
    ;;      len   Number of bytes to read. If non numeric, less
    ;;            than 1 or greater than the number of bytes in
    ;;            the file everything is returned.
   
    (vl-catch-all-apply
       '(lambda ( / iomode format size )
            (setq
                iomode   1 ;; 1 = read, 2 = write, 8 = append
                format   0 ;; 0 = ascii, -1 = unicode, -2 = system default
                fso      (vlax-create-object "Scripting.FileSystemObject")
                file     (vlax-invoke fso 'GetFile path)
                stream   (vlax-invoke fso 'OpenTextFile path iomode format)
                size     (vlax-get file 'Size)
                len      (if (and (numberp len) (< 0 len size)) (fix len) size)
                result   (vlax-invoke stream 'read len)
            )
            (vlax-invoke stream 'Close)
        )
    )
   
    (if stream (vlax-release-object stream))
    (if file (vlax-release-object file))
    (if fso (vlax-release-object fso))
   
    result

)

(defun _WriteStream ( path text mode / fso stream file result )

    ;;  Return the file size if the file is successfully written
    ;;  to, otherwise nil. Will write all ascii chars to file
    ;;  including nulls. If the caller wants to pass a list of
    ;;  byte values to the function just call it like so:
    ;;
    ;;      (_WriteStream
    ;;          path
    ;;          (vl-list->string '(87 111 111 116 33))
    ;;          mode
    ;;      )
    ;;
    ;;  Arguments:
    ;;
    ;;      path  <duh>
    ;;      text  <duh>
    ;;      mode  "a" to create/append,
    ;;            "w" to create/overwrite (default)
   
    (setq mode (if (member mode '("a" "A")) "a" "w"))
   
    (vl-catch-all-apply
       '(lambda ( / format )
            (setq fso (vlax-create-object "Scripting.FileSystemObject"))
            (cond
                (   (or (null (findfile path)) (eq "w" mode))
                    (setq stream
                        (vlax-invoke
                            fso
                           'CreateTextFile
                            path
                           -1 ;; 0 (false) = don't overwrite , -1 (true) = overwrite
                            0 ;; 0 (false) = ascii, -1 (true) = unicode
                        )
                    )
                    (setq file (vlax-invoke fso 'GetFile path))
                )
                (   (setq file (vlax-invoke fso 'GetFile path))
                    (setq stream
                        (vlax-invoke
                            file
                           'OpenAsTextStream
                            8 ;; 1 = read, 2 = write, 8 = append
                            0 ;; 0 = ascii, -1 = unicode, -2 system default
                        )
                    )       
                )
            )
            (vlax-invoke stream 'Write text)
            (vlax-invoke stream 'Close)
            (setq result (vlax-get file 'Size))
        )
    )

    (if file (vlax-release-object file))
    (if stream (vlax-release-object stream))
    (if fso (vlax-release-object fso))
   
    result
   
)

The attached zip contains 5 files:
default.stb (STB that comes with Bricscad 440 bytes)
default_Minus_60_Bytes.stb (STB created by my code: only 290 bytes)
default_Minus_60_Bytes.txt (default_Minus_60_Bytes.stb after decompression)
MANUAL_default_Minus_60_Bytes.stb (STB created "manually" with correct file size)
MANUAL_default_Minus_60_Bytes.txt (MANUAL_default_Minus_60_Bytes.stb after decompression)

« Last Edit: May 05, 2012, 06:48:39 PM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #3 on: May 06, 2012, 04:12:23 AM »
I have to correct my previous post. MP's read function does read the complete stb file. But the string value it returns does not completely display in the command history window. I am assuming this is caused by certain special characters.

The test function returns T.

Code: [Select]
(defun Read_Test ( / list_LM list_MP)
  (setq list_LM (vlax-safearray->list (vlax-variant-value (LM:ReadBinaryStream "default.stb" 0))))
  (setq list_MP (vl-string->list (_ReadStream "default.stb" 0)))
  (and
    (= (length list_LM) 440)
    (= (length list_MP) 440)
    (vl-every
      '=
      list_LM
      list_MP
    )
  )
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #4 on: May 06, 2012, 06:46:21 AM »
OK, the code below works.

As mentioned in a previous post the code requires this dll:
http://www.dogma.net/markn/ZlibOCX2.dll
It is mentioned on http://www.zlib.net/ as "unsupported VB5 binary".
This dll reads and writes files.
The dll must be registered using regsvr32.exe.

Code: [Select]
; (PlotStyleTable_To_TextFile "default.ctb" (strcat (getvar 'dwgprefix) "default_ctb.txt"))
; (PlotStyleTable_To_TextFile "default.stb" (strcat (getvar 'dwgprefix) "default_stb.txt"))
(defun PlotStyleTable_To_TextFile (PlotStyleTableFileName txtFileName / N_ChopFirst60Bytes N_Decompress)

  (defun N_ChopFirst60Bytes (inputFilename outputFilename / adoStream content)
    (setq adoStream (vlax-create-object "ADODB.Stream"))
    (vlax-put-property adoStream 'type 1)
    (vlax-invoke adoStream 'open)
    (vlax-invoke adoStream 'loadfromfile inputFilename)
    (vlax-put-property adoStream 'position 60)
    (setq content (vlax-invoke-method adoStream 'read -1))
    (vlax-invoke adoStream 'close)
    (vlax-invoke adoStream 'open)
    (vlax-invoke adoStream 'write content)
    (vlax-invoke adoStream 'savetofile outputFilename 2)
    (vlax-release-object adoStream)
  )
 
  (defun N_Decompress (inputFilename outputFilename / zlibif)
    (setq zlibif (vlax-create-object "zlibIF.zlibIF.1"))
    (vlax-put zlibif 'inputfilename inputFilename)
    (vlax-put zlibif 'outputfilename outputFilename)
    (vlax-invoke zlibif 'decompress)
    (vlax-release-object zlibif)
  )
 
  (not
    (vl-catch-all-error-p
      (vl-catch-all-apply
        '(lambda ( / tmpFileName)
          (setq tmpFileName (vl-filename-mktemp nil nil ".zl"))
          (N_ChopFirst60Bytes PlotStyleTableFileName tmpFileName)
          (N_Decompress tmpFileName txtFileName)
          (vl-file-delete tmpFileName)
        )
      )
    )
  )
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #5 on: May 06, 2012, 12:15:20 PM »
Well, not all sorted of course. My code still has to parse the text file. This very doable, but I will leave that for now.

One "burning" question remains:
Can you actually write a binary file using Lisp?
(LM:WriteBinaryStream) seems to require a variant of the type 8209 which I was unable to create. MP's (_WriteStream) will work. But if the "ascii-index-list" contains a zero value, that value and everything after will be skipped (see my second post).

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: How to get plot style names from STB file?
« Reply #6 on: May 06, 2012, 02:43:43 PM »
One "burning" question remains:
Can you actually write a binary file using Lisp?
(LM:WriteBinaryStream) seems to require a variant of the type 8209 which I was unable to create. MP's (_WriteStream) will work. But if the "ascii-index-list" contains a zero value, that value and everything after will be skipped (see my second post).

To directly answer your question: you can write a binary stream using LISP by interfacing with the ADODB.Stream Object (as per my LM:WriteBinaryStream function), however, to do so requires that you do not convert to a list the Variant returned by a similar function used to read a binary stream, as this variant cannot be created using LISP (as you have already discovered).

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #7 on: May 07, 2012, 03:20:53 PM »
Lee, thank you for that clarification.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: How to get plot style names from STB file?
« Reply #8 on: May 07, 2012, 05:28:34 PM »
Lee, thank you for that clarification.

You're very welcome, though unfortunately it doesn't help you toward a solution  :-(

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #9 on: May 28, 2014, 10:35:24 AM »
OK, the code below works.

As mentioned in a previous post the code requires this dll:
http://www.dogma.net/markn/ZlibOCX2.dll
It is mentioned on http://www.zlib.net/ as "unsupported VB5 binary".
This dll reads and writes files.
The dll must be registered using regsvr32.exe.

Code: [Select]
; (PlotStyleTable_To_TextFile "default.ctb" (strcat (getvar 'dwgprefix) "default_ctb.txt"))
; (PlotStyleTable_To_TextFile "default.stb" (strcat (getvar 'dwgprefix) "default_stb.txt"))

Hello Roy,
when I read your post this, I was very very happy!
For two days I'm looking for a solution to read the settings in CTB files.
Unfortunately, I was not able to use your code.
Is not output any error, but I can not find the file TXT :cry:

I'll explain what I did:
  • I registered ZlibOCX2.dll with regsvr32.exe
  • I prepared this lisp file with your code:
Code: [Select]
(defun c:test.lsp ()
  (vl-load-com)
  (PlotStyleTable_To_TextFile "c:\\prova.ctb" "c:\\prova_ctb.txt")
  (alert "Do!!")
)

; (PlotStyleTable_To_TextFile "default.ctb" (strcat (getvar 'dwgprefix) "default_ctb.txt"))
; (PlotStyleTable_To_TextFile "default.stb" (strcat (getvar 'dwgprefix) "default_stb.txt"))
(defun PlotStyleTable_To_TextFile (PlotStyleTableFileName txtFileName / N_ChopFirst60Bytes N_Decompress)

  (defun N_ChopFirst60Bytes (inputFilename outputFilename / adoStream content)
    (setq adoStream (vlax-create-object "ADODB.Stream"))
    (vlax-put-property adoStream 'type 1)
    (vlax-invoke adoStream 'open)
    (vlax-invoke adoStream 'loadfromfile inputFilename)
    (vlax-put-property adoStream 'position 60)
    (setq content (vlax-invoke-method adoStream 'read -1))
    (vlax-invoke adoStream 'close)
    (vlax-invoke adoStream 'open)
    (vlax-invoke adoStream 'write content)
    (vlax-invoke adoStream 'savetofile outputFilename 2)
    (vlax-release-object adoStream)
  )
 
  (defun N_Decompress (inputFilename outputFilename / zlibif)
    (setq zlibif (vlax-create-object "zlibIF.zlibIF.1"))
    (vlax-put zlibif 'inputfilename inputFilename)
    (vlax-put zlibif 'outputfilename outputFilename)
    (vlax-invoke zlibif 'decompress)
    (vlax-release-object zlibif)
  )
 
  (not
    (vl-catch-all-error-p
      (vl-catch-all-apply
        '(lambda ( / tmpFileName)
          (setq tmpFileName (vl-filename-mktemp nil nil ".zl"))
          (N_ChopFirst60Bytes PlotStyleTableFileName tmpFileName)
          (N_Decompress tmpFileName txtFileName)
          (vl-file-delete tmpFileName)
        )
      )
    )
  )
)
  • I started the "c:test" function
  • No error in AutoCAD but the file 'test.txt' was not created  :cry:

Can you help me understand where is the problem?

Thanks in advance.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #10 on: May 28, 2014, 12:09:11 PM »
Lupo76, your code has a function "c:test.lsp". But you say you have started the "c:test" function. Is this a typo or are you mixing up two functions?

If there is no mix-up you can try debugging your problem using the following procedure:
1.
Load the nested functions N_ChopFirst60Bytes and N_Decompress as separate unnested functions.
2.
Run these three lines of code one by one from the command line and check for errors:
Code: [Select]
(setq tmpFileName (vl-filename-mktemp nil nil ".zl"))
(N_ChopFirst60Bytes "c:\\prova.ctb" tmpFileName)
(N_Decompress tmpFileName "c:\\prova_ctb.txt")

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #11 on: May 29, 2014, 02:34:35 AM »
Lupo76, your code has a function "c:test.lsp". But you say you have started the "c:test" function. Is this a typo or are you mixing up two functions?

sorry! you're right! was a distraction

If there is no mix-up you can try debugging your problem using the following procedure:
1.
Load the nested functions N_ChopFirst60Bytes and N_Decompress as separate unnested functions.
2.
Run these three lines of code one by one from the command line and check for errors:
Code: [Select]
(setq tmpFileName (vl-filename-mktemp nil nil ".zl"))
(N_ChopFirst60Bytes "c:\\prova.ctb" tmpFileName)
(N_Decompress tmpFileName "c:\\prova_ctb.txt")

Here are the test results:
Comando: (LOAD "C:/prova2.lsp") N_DECOMPRESS

Comando: (setq tmpFileName (vl-filename-mktemp nil nil ".zl"))
"C:\\DOCUME~1\\Anonimo\\IMPOST~1\\Temp\\$VL~~005.zl"

Comando: (N_ChopFirst60Bytes "c:\\prova.ctb" tmpFileName)
; error: ADODB.Stream: Arguments are of the wrong type, are not
the range, or are in conflict.

may depend on what?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #12 on: May 29, 2014, 05:58:12 AM »
may depend on what?
I am not sure.

Try the alternative code below. It uses MP's _ReadStream and _WriteStream* avoiding any ADO issues. In my tests N_ChopFirst60Bytes and N_ChopFirst60Bytes_MP produce identical results.

*The current version of BricsCAD no longer has a problem with MP's functions (fixed in V12). And BricsCAD now even has built-in Lisp functions for reading and writing binary files.

Code: [Select]
(defun N_ChopFirst60Bytes_MP (inputFilename outputFilenam / bytes stream)
  (if (setq stream (_ReadStream inputFilename nil))
    (progn
      (setq bytes (vl-string->list stream))
      (repeat 15 (setq bytes (cddddr bytes))) ; Chop away first 60.
      (_WriteStream outputFilenam (vl-list->string bytes) "w")
    )
  )
)
« Last Edit: May 29, 2014, 06:07:50 AM by roy_043 »

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #13 on: May 29, 2014, 08:04:24 AM »
Perfect! thanks now it works!  :-)

However I can not understand the values ​​in the text file

eg. in the CTB, the color "5" has been set with the printed color "Red" (1)

In the TXT file I find the following listing

 5{
  name="Color_6
  localized_name="Color_6
  description="
  color=-1006698496
  mode_color=-1006698496
  color_policy=5
  physical_pen_number=0
  virtual_pen_number=0
  screen=100
  linepattern_size=0.5
  linetype=31
  adaptive_linetype=TRUE
  lineweight=25
  fill_style=73
  end_style=4
  join_style=5
 }

I guess the color "Red" matches "color = -1006698496" right?
There is a table of correspondence of these colors? or I have to realize I?

PS. I'm doing this because I need to read in a CTB file, the corresponding color printing, of a color screen.
Maybe there's lisp code in the web that already does this?
With the list above I can program a function of this type, but is much work to do!  :cry:
If there is something ready would be very nice!  :lmao:

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #14 on: May 29, 2014, 01:08:40 PM »
I guess the color "Red" matches "color = -1006698496" right?
Yes. The value should be split up into 4 bytes:
Code: [Select]
(defun ColorInteger_To_ByteList (integer)
  (list
    (lsh integer -24)
    (lsh (lsh integer 8) -24)
    (lsh (lsh integer 16) -24)
    (lsh (lsh integer 24) -24)
  )
)

Code: [Select]
(ColorInteger_To_ByteList -1006698496) => (195 255 0 0)If the top byte is 195 the color is an ACI color.
If it is 194 it is a true color.
The other bytes are the R, G and B values (in that order in the list).
« Last Edit: May 29, 2014, 01:25:30 PM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #15 on: May 30, 2014, 03:14:33 AM »
Actually for true colors the mode_color value represents the print color. I don't understand the color value in this case. It is not the ACI 'equivalent' of the true color.

Code: [Select]
Style property Color: RGB:91,46,209:
  color=-1012575662       (ColorInteger_To_ByteList -1012575662) => (195 165 82 82) => ???
  mode_color=-1034211631  (ColorInteger_To_ByteList -1034211631) => (194 91 46 209) => Print color
 
Style property Color: RGB:91,46,230:
  color=-1006698433       (ColorInteger_To_ByteList -1006698433) => (195 255 0 63)  => ???
  mode_color=-1034211610  (ColorInteger_To_ByteList -1034211610) => (194 91 46 230) => Print color

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #16 on: June 13, 2014, 12:12:36 PM »
Actually for true colors the mode_color value represents the print color. I don't understand the color value in this case. It is not the ACI 'equivalent' of the true color.

Code: [Select]
Style property Color: RGB:91,46,209:
  color=-1012575662       (ColorInteger_To_ByteList -1012575662) => (195 165 82 82) => ???
  mode_color=-1034211631  (ColorInteger_To_ByteList -1034211631) => (194 91 46 209) => Print color
 
Style property Color: RGB:91,46,230:
  color=-1006698433       (ColorInteger_To_ByteList -1006698433) => (195 255 0 63)  => ???
  mode_color=-1034211610  (ColorInteger_To_ByteList -1034211610) => (194 91 46 230) => Print color

Hello Roy,
sorry for the delay in my response, but unfortunately lately I've been very busy with other projects.

Thank you very much for your help, I can finally see some light in this project management CTB.

I found the following function, which converts the RGB color ACI:

Code: [Select]
(defun rgbtoaci (rgbcodes / colorobj)
  (vl-load-com)
  (setq colorobj (vla-getinterfaceobject (vlax-get-acad-object) "AutoCAD.AcCmColor.18"))
  (vla-setrgb colorobj (car rgbcodes) (cadr rgbcodes) (caddr rgbcodes))
  (vla-get-colorindex colorobj)
)

Unfortunately it does not work correctly with some colors.
For example.

(rgbtoaci '(221 0 0))) => 12 it's ok!
(rgbtoaci '(184 0 0))) => 12 it's no correct! the correct value is 14

Can you explain to me why this problem?
Do you have any advice?

thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #17 on: June 14, 2014, 05:18:26 AM »
(rgbtoaci '(184 0 0))) => 12 it's no correct! the correct value is 14
I get the same result in BricsCAD. But why do you say this is wrong?

The ACI color dialog has these RGB values for index 12 and 14:
ACI=12: R=204, G=0, B=0.
ACI=14: R=153, G=0, B=0.

Since 184 is closer to 204 than to 153 the return value of rgbtoaci seems to be correct.
But I do not fully understand the rgb to aci conversion.

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #18 on: June 14, 2014, 05:52:54 AM »
I say it's wrong because I set the CTB in the following way:

Color 12 -> Print Color = 12
Color 14 -> Print Color = 14

I subsequently exported to a txt file all settings of the CTB and found
Color 12 -> mode_color = -1008926720 = (221 0 0)
Color 14 -> mode_color = -1011351552 = (184 0 0)

Then I converted the RGB color in ACI and unfortunately I found out that:

(221 0 0) = 12, OK
(184 0 0) = 12, NO OK

I need to get the same colors ACI set in CTB!
I think that the only solution is to prepare a file mapping of the RGB -> ACI, but I hope in some of your advice to avoid doing this.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How to get plot style names from STB file?
« Reply #19 on: June 14, 2014, 05:27:56 PM »
The situation is more complex than I previously thought.

The 194/195 logic (as used in VP layer color overrides) does not fully apply. And very strange is the fact that the 'color' values for Color_12 and Color_14 are the same. But in BricsCAD the 'mode_color' value always seems to contain the correct RGB values. So I don't understand why AutoCAD is giving different values.

In the end creating a mapping table may indeed be the best option.

Code: [Select]
Color_1
  color      (ColorInteger_To_ByteList -1006698496) => (195 255   0   0)
  mode_color (ColorInteger_To_ByteList -1006698496) => (195 255   0   0)
Color_2
  color      (ColorInteger_To_ByteList -1006633216) => (195 255 255   0)
  mode_color (ColorInteger_To_ByteList -1006633216) => (195 255 255   0)
Color_3
  color      (ColorInteger_To_ByteList -1023344896) => (195   0 255   0)
  mode_color (ColorInteger_To_ByteList -1023344896) => (195   0 255   0)

Color_11
  color      (ColorInteger_To_ByteList -1006665857) => (195 255 127 127)
  mode_color (ColorInteger_To_ByteList -1006665857) => (195 255 127 127)
Color_12
  color      (ColorInteger_To_ByteList -1023410011) => (195   0   0 165)
  mode_color (ColorInteger_To_ByteList -1026818048) => (194 204   0   0)
Color_13
  color      (ColorInteger_To_ByteList -1018009691) => (195  82 103 165)
  mode_color (ColorInteger_To_ByteList -1026791834) => (194 204 102 102)
Color_14
  color      (ColorInteger_To_ByteList -1023410011) => (195   0   0 165)
  mode_color (ColorInteger_To_ByteList -1030160384) => (194 153   0   0)
Color_15
  color      (ColorInteger_To_ByteList -1018015067) => (195  82  82 165)
  mode_color (ColorInteger_To_ByteList -1030140852) => (194 153  76  76)

Lupo76

  • Bull Frog
  • Posts: 343
Re: How to get plot style names from STB file?
« Reply #20 on: June 16, 2014, 03:32:27 AM »
In the end creating a mapping table may indeed be the best option.
]

I decided
I will create a mapping table

Thanks for all the help!