Author Topic: Block Preview Icon  (Read 10116 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
Re: Block Preview Icon
« Reply #15 on: January 03, 2009, 09:18:29 AM »
Oh, wait, maybe I CAN use that.

I was looking closer at his usage statements, and this one looks different than some of the other ones I've seen on his site.  I've had to ignore things on his site before because of his strict allowances, but this one looks like it will let me use it.  At least, if I'm reading it correctly....

sinc

  • Guest
Re: Block Preview Icon
« Reply #16 on: January 03, 2009, 09:51:06 AM »
I discovered that I can actually completely sidestep the issue, and avoid any possible problems by not using Tony's code.  Then I know for sure that I'm not going awry with any of his usage terms.

Instead, all I have to do is define this PInvoke call:

Code: [Select]
[SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
extern static int acedCmd(IntPtr resbuf);

Then just do this:

Code: [Select]
using (ResultBuffer rb = new ResultBuffer())
{
     rb.Add(new TypedValue(5005, "._BLOCKICON"));
     rb.Add(new TypedValue(5005, blockName));
     acedCmd(rb.UnmanagedObject);
}

Problem solved!
« Last Edit: January 03, 2009, 10:15:05 AM by sinc »

TonyT

  • Guest
Re: Block Preview Icon
« Reply #17 on: January 04, 2009, 08:09:18 AM »

I discovered that I can actually completely sidestep the issue, and avoid any possible problems by not using Tony's code.  Then I know for sure that I'm not going awry with any of his usage terms.


The only usage term is that the copyright notice appear in the credits
of any software you distribute that includes that code.

Have a problem with that?

Actually, you should probably consider crediting theswamp.org in
your application's credits, for helping you to the extent that it has,
which goes way beyond only what you've learned from my code.


sinc

  • Guest
Re: Block Preview Icon
« Reply #18 on: January 04, 2009, 09:39:06 AM »
No, Tony, I have no problem with that, except for the fact that the legalese is difficult to interpret and parse.  Whenever someone posts lengthy legalese like that, it beholdens others to have to read and interpret it.

But as I said, once I took the time to carefully read this particular usage statement, I came back and said that it DID look like I could use it (although I am now certain I won't, because of this thread).  My comment was more because of a couple of other times I ended up on your site while researching a problem, and the other things I saw had a much more strict usage statement.  I did not read this one carefully, and just assumed it was the same as you other statements I had seen in the past.  I actually basically never go to your site, except for very very very very very rare occasions, because those first statements I saw did not give me the allowance to use the things you were posting.  I decided that, even though your site may be useful, it's not so useful if everything is restricted, so I stopped even looking at it.  This was the first time I've even looked at your site in I-don't-know-how-many-months.  And now, I do not intend to ever look at your site again.

And if you really think I should credit the Swamp in my application, then what should I do with all the other sources of teaching I've had over the years?  In a lengthy career in software development, I've learned far, far, far, far, far more from other sources than I have from the Swamp.  So where does it end?  How many people do I have to credit in my application?   How many people do YOU credit in YOUR applications?  After all, you learned what you know from SOMEWHERE.  You weren't born with the knowledge.

TonyT

  • Guest
Re: Block Preview Icon
« Reply #19 on: January 04, 2009, 10:16:16 AM »
I don't see how the legalese is difficult to parse. 

I made it completely free for any purpose whatsoever, with the
only condition that I'm credited for using it. If you would rather
not give credit, that's fine, but there's no need to distort that.

No, Tony, I have no problem with that, except for the fact that the legalese is difficult to interpret and parse.  Whenever someone posts lengthy legalese like that, it beholdens others to have to read and interpret it.

But as I said, once I took the time to carefully read this particular usage statement, I came back and said that it DID look like I could use it (although I am now certain I won't, because of this thread).  My comment was more because of a couple of other times I ended up on your site while researching a problem, and the other things I saw had a much more strict usage statement.  I did not read this one carefully, and just assumed it was the same as you other statements I had seen in the past.  I actually basically never go to your site, except for very very very very very rare occasions, because those first statements I saw did not give me the allowance to use the things you were posting.  I decided that, even though your site may be useful, it's not so useful if everything is restricted, so I stopped even looking at it.  This was the first time I've even looked at your site in I-don't-know-how-many-months.  And now, I do not intend to ever look at your site again.

And if you really think I should credit the Swamp in my application, then what should I do with all the other sources of teaching I've had over the years?  In a lengthy career in software development, I've learned far, far, far, far, far more from other sources than I have from the Swamp.  So where does it end?  How many people do I have to credit in my application?   How many people do YOU credit in YOUR applications?  After all, you learned what you know from SOMEWHERE.  You weren't born with the knowledge.

pb.Perksa

  • Guest
Re: Block Preview Icon
« Reply #20 on: March 22, 2009, 07:56:06 PM »
Sigh... Tony Tony Tony... (as in Tanzillo).  You really are your own worst enemy sometimes mate.  You really know your stuff, but getting past the invective is hard, and over the years, I've learned its just more effort than its worth reading your stuff.  It's easier just to ignore it and get it from another source. 

Anyways...

The best method I've ever found for extracting the image preview from a drawing (and certainly the fastest) is something I found on codeproject long ago...

http://www.codeproject.com/KB/vbscript/VBDwgImageExtractor.aspx

I used this code to create a block directory list program, that read the bitmaps out of each file on-the-fly.  Now I just point my external app at the directory from a tool-palette, and drop the blocks where I need to maintain an appropriate discipline-based grouping.

pb.Perksa

  • Guest
Re: Block Preview Icon
« Reply #21 on: March 22, 2009, 08:00:27 PM »
This is it in my VB.NET application.  I'd appreciate if someone actually took the time to do this in C# some time... It should be fairly straight-forward to modify one would assume...

Just pass the filename, and the picturebox to the function, and voila.

Best part about it is that it doesn't require AutoCAD at all.

Quote
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.ApplicationServices
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Imports System.Windows.forms

Module modACADIconPreview

   Public Function ACADIconPreview(ByVal strFile As String, ByVal picBox As PictureBox) As Integer
      Dim Num1 As Integer = 1
      Dim imgVal1 As Image = Nothing

      ' Create the reader for data.
      Dim fs As FileStream = New FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
      Dim r As BinaryReader = New BinaryReader(fs)

      ' Get the image position in the DWG file
      r.BaseStream.Seek(&HD, SeekOrigin.Begin)
      Dim imgPos As Int32 = r.ReadInt32()
      r.BaseStream.Seek(imgPos, SeekOrigin.Begin)

      ' Image sentinel to check if the image data

      ' is not corrupted
      Dim imgBSentinel() As Byte = {&H1F, &H25, &H6D, &H7, &HD4, &H36, &H28, &H28, &H9D, &H57, &HCA, &H3F, &H9D, &H44, &H10, &H2B}

      ' Read Image sentinel
      Dim imgCSentinel(16) As Byte
      imgCSentinel = r.ReadBytes(16)

      ' if image sentinel is correct
      If (imgBSentinel.ToString() = imgCSentinel.ToString()) Then
         ' Get image size
         Dim imgSize As UInt32 = r.ReadUInt32()

         ' Get number of images present
         Dim imgPresent As Byte = r.ReadByte()

         ' header
         Dim imgHeaderStart As Int32 = 0
         Dim imgHeaderSize As Int32 = 0

         ' bmp data
         Dim imgBmpStart As Int32 = 0
         Dim imgBmpSize As Int32 = 0
         Dim bmpDataPresent As Boolean = False

         ' wmf data
         Dim imgWmfStart As Int32
         Dim imgWmfSize As Int32
         Dim wmfDataPresent As Boolean = False

         ' get each image present
         For I As Integer = 1 To imgPresent
            ' Get image type

            Dim imgCode As Byte = r.ReadByte()
            Select Case imgCode

               Case 1
                  ' Header data
                  imgHeaderStart = r.ReadInt32()
                  imgHeaderSize = r.ReadInt32()
               Case 2
                  ' bmp data
                  imgBmpStart = r.ReadInt32()
                  imgBmpSize = r.ReadInt32()
                  bmpDataPresent = True
               Case 3
                  ' wmf data
                  imgWmfStart = r.ReadInt32()
                  imgWmfSize = r.ReadInt32()
                  wmfDataPresent = True
            End Select

         Next

         If (bmpDataPresent) Then

            r.BaseStream.Seek(imgBmpStart, SeekOrigin.Begin)

            Dim tempPixelData(imgBmpSize + 14) As Byte

            ' indicate it is a bit map
            tempPixelData(0) = &H42
            tempPixelData(1) = &H4D

            ' offBits
            tempPixelData(10) = &H36
            tempPixelData(11) = &H4

            Dim tempBuffData(imgBmpSize) As Byte

            tempBuffData = r.ReadBytes(imgBmpSize)
            tempBuffData.CopyTo(tempPixelData, 14)

            Dim memStream As MemoryStream = New MemoryStream(tempPixelData)
            Dim bmp As Bitmap = New Bitmap(memStream)
            Dim szBmp As System.Drawing.Size
            szBmp.Width = picBox.Width
            szBmp.Height = picBox.Height
            Dim bmpResize As Bitmap = New Bitmap(bmp, szBmp)   'resize the bitmap for the picturebox

            picBox.Image = bmpResize

         End If

         If (wmfDataPresent) Then
            ' read imgWmfSize wmf data

         End If

         Dim imgESentinel() As Byte = {&HE0, &HDA, &H92, &HF8, &H2B, &HC9, &HD7, &HD7, &H62, &HA8, &H35, &HC0, &H62, &HBB, &HEF, &HD4}
         imgCSentinel = r.ReadBytes(16)

         ' if image sentinel is correct
         If (imgESentinel.ToString() = imgCSentinel.ToString()) Then
            ' Image data is not corrupted

         End If

      End If

      fs.Close()
     
   End Function

End Module
« Last Edit: March 22, 2009, 08:05:27 PM by pb.Perksa »

pb.Perksa

  • Guest
Re: Block Preview Icon
« Reply #22 on: June 09, 2009, 08:17:18 PM »
bump

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1363
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #23 on: June 09, 2009, 09:42:13 PM »


UHMmmmm  ... what's the bump for ?
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6929
  • AKA Daniel
Re: Block Preview Icon
« Reply #24 on: June 09, 2009, 10:31:19 PM »
.

bikelink

  • Guest
Re: Block Preview Icon
« Reply #25 on: November 17, 2009, 01:12:05 AM »
my job for c#

 public static void  ACADIconPreview(String strFile  , PictureBox  picBox  )
         {
            int Num1 = 1;
            Image imgVal1 = null;

             
             System.IO.FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader r   = new  BinaryReader(fs);


              // Get the image position in the DWG file
             long l = byte.Parse("D", NumberStyles.AllowHexSpecifier);
              r.BaseStream.Seek(l, SeekOrigin.Begin);
              int  imgPos  = r.ReadInt32 ();
              r.BaseStream.Seek(imgPos, SeekOrigin.Begin);

      // Image sentinel to check if the image data
   
      // is not corrupted
      Encoding unicode = Encoding.Unicode;


      Byte[] imgBSentinel = { byte.Parse("1F", NumberStyles.AllowHexSpecifier),
                            byte.Parse("25",  NumberStyles.AllowHexSpecifier),
                            byte.Parse("6D", NumberStyles.AllowHexSpecifier), 
                            byte.Parse("7", NumberStyles.AllowHexSpecifier),  byte.Parse("D4", NumberStyles.AllowHexSpecifier), 
             byte.Parse("36", NumberStyles.AllowHexSpecifier),  byte.Parse("28", NumberStyles.AllowHexSpecifier), 
             byte.Parse("28", NumberStyles.AllowHexSpecifier),  byte.Parse("9D", NumberStyles.AllowHexSpecifier),  byte.Parse("57", NumberStyles.AllowHexSpecifier),
            byte.Parse("CA", NumberStyles.AllowHexSpecifier), 
             byte.Parse("3F", NumberStyles.AllowHexSpecifier),  byte.Parse("9D", NumberStyles.AllowHexSpecifier),
            byte.Parse("44", NumberStyles.AllowHexSpecifier),  byte.Parse("10", NumberStyles.AllowHexSpecifier), 
             byte.Parse("2B", NumberStyles.AllowHexSpecifier)
         };

      // Read Image sentinel
      Byte[] imgCSentinel = new Byte[16];
      imgCSentinel = r.ReadBytes(16);

      // if image sentinel is correct
      if  (imgBSentinel.ToString() == imgCSentinel.ToString())
      {
         // Get image size
         int imgSize  = r.ReadInt32 ();

         // Get number of images present
         Byte imgPresent   = r.ReadByte();

         // header
         int imgHeaderStart   = 0;
         int  imgHeaderSize   = 0;

         // bmp data
         int imgBmpStart   = 0;
         int imgBmpSize   = 0;
         bool  bmpDataPresent  = false;

         // wmf data
         int imgWmfStart , imgWmfSize ;
         bool wmfDataPresent  = false;

         // get each image present
         for(int Iint = 0 ; Iint < imgPresent; Iint++)
         {

               Byte  imgCode  = r.ReadByte();
               switch(imgCode)
               {
                   case 1:
                      // Header data
                      imgHeaderStart = r.ReadInt32 ();
                      imgHeaderSize = r.ReadInt32();
                      break;
                   case 2:
                      // bmp data
                      imgBmpStart = r.ReadInt32();
                      imgBmpSize = r.ReadInt32();
                      bmpDataPresent = true;
                      break;
                   case 3:
                      // wmf data
                      imgWmfStart = r.ReadInt32();
                      imgWmfSize = r.ReadInt32();
                      wmfDataPresent = true;
                      break;
                   default:
                       break;
             }

        }

         if (bmpDataPresent)
         {

            r.BaseStream.Seek(imgBmpStart, SeekOrigin.Begin);

            Byte[]  tempPixelData =new byte[imgBmpSize + 14];

            // indicate it is a bit map
            tempPixelData[0] = byte.Parse("H42", CultureInfo.InvariantCulture);
            tempPixelData[1] = byte.Parse("H4D", CultureInfo.InvariantCulture);

            // offBits
            tempPixelData[10] = byte.Parse("H36", CultureInfo.InvariantCulture);
            tempPixelData[11] =  byte.Parse("H4", CultureInfo.InvariantCulture);

            Byte[]  tempBuffData = new byte[imgBmpSize] ;

            tempBuffData = r.ReadBytes(imgBmpSize);
            tempBuffData.CopyTo(tempPixelData, 14);

            MemoryStream memStream  = new  MemoryStream(tempPixelData);
            Bitmap  bmp  = new Bitmap(memStream);
            Size szBmp = new System.Drawing.Size();
            szBmp.Width = picBox.Width;
            szBmp.Height = picBox.Height;
           Bitmap  bmpResize  = new Bitmap(bmp, szBmp)  ;
            picBox.Image = bmpResize;

         }

         
          // read imgWmfSize wmf data
         if (wmfDataPresent)
         {}
           
       
         Byte[] imgESentinel = {byte.Parse("E0", NumberStyles.AllowHexSpecifier),
             byte.Parse("DA", NumberStyles.AllowHexSpecifier), byte.Parse("92", NumberStyles.AllowHexSpecifier),
             byte.Parse("F8", NumberStyles.AllowHexSpecifier), byte.Parse("2B", NumberStyles.AllowHexSpecifier),
             byte.Parse("C9", NumberStyles.AllowHexSpecifier), byte.Parse("D7", NumberStyles.AllowHexSpecifier),
             byte.Parse("D7", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
             byte.Parse("A8", NumberStyles.AllowHexSpecifier), byte.Parse("35", NumberStyles.AllowHexSpecifier),
             byte.Parse("C0", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
             byte.Parse("BB", NumberStyles.AllowHexSpecifier), byte.Parse("EF", NumberStyles.AllowHexSpecifier),
             byte.Parse("D4", NumberStyles.AllowHexSpecifier)};         


         imgCSentinel = r.ReadBytes(16);

         // if image sentinel is correct
         if (imgESentinel.ToString() == imgCSentinel.ToString())
         {}
         

      }

      fs.Close();
     
         }

rodrigo_gcmsoft

  • Guest
Re: Block Preview Icon
« Reply #26 on: April 02, 2011, 11:06:40 PM »
my job for c#

 public static void  ACADIconPreview(String strFile  , PictureBox  picBox  )
         {
            int Num1 = 1;
            Image imgVal1 = null;

             
             System.IO.FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader r   = new  BinaryReader(fs);


              // Get the image position in the DWG file
             long l = byte.Parse("D", NumberStyles.AllowHexSpecifier);
              r.BaseStream.Seek(l, SeekOrigin.Begin);
              int  imgPos  = r.ReadInt32 ();
              r.BaseStream.Seek(imgPos, SeekOrigin.Begin);

      // Image sentinel to check if the image data
   
      // is not corrupted
      Encoding unicode = Encoding.Unicode;


      Byte[] imgBSentinel = { byte.Parse("1F", NumberStyles.AllowHexSpecifier),
                            byte.Parse("25",  NumberStyles.AllowHexSpecifier),
                            byte.Parse("6D", NumberStyles.AllowHexSpecifier), 
                            byte.Parse("7", NumberStyles.AllowHexSpecifier),  byte.Parse("D4", NumberStyles.AllowHexSpecifier), 
             byte.Parse("36", NumberStyles.AllowHexSpecifier),  byte.Parse("28", NumberStyles.AllowHexSpecifier), 
             byte.Parse("28", NumberStyles.AllowHexSpecifier),  byte.Parse("9D", NumberStyles.AllowHexSpecifier),  byte.Parse("57", NumberStyles.AllowHexSpecifier),
            byte.Parse("CA", NumberStyles.AllowHexSpecifier), 
             byte.Parse("3F", NumberStyles.AllowHexSpecifier),  byte.Parse("9D", NumberStyles.AllowHexSpecifier),
            byte.Parse("44", NumberStyles.AllowHexSpecifier),  byte.Parse("10", NumberStyles.AllowHexSpecifier), 
             byte.Parse("2B", NumberStyles.AllowHexSpecifier)
         };

      // Read Image sentinel
      Byte[] imgCSentinel = new Byte[16];
      imgCSentinel = r.ReadBytes(16);

      // if image sentinel is correct
      if  (imgBSentinel.ToString() == imgCSentinel.ToString())
      {
         // Get image size
         int imgSize  = r.ReadInt32 ();

         // Get number of images present
         Byte imgPresent   = r.ReadByte();

         // header
         int imgHeaderStart   = 0;
         int  imgHeaderSize   = 0;

         // bmp data
         int imgBmpStart   = 0;
         int imgBmpSize   = 0;
         bool  bmpDataPresent  = false;

         // wmf data
         int imgWmfStart , imgWmfSize ;
         bool wmfDataPresent  = false;

         // get each image present
         for(int Iint = 0 ; Iint < imgPresent; Iint++)
         {

               Byte  imgCode  = r.ReadByte();
               switch(imgCode)
               {
                   case 1:
                      // Header data
                      imgHeaderStart = r.ReadInt32 ();
                      imgHeaderSize = r.ReadInt32();
                      break;
                   case 2:
                      // bmp data
                      imgBmpStart = r.ReadInt32();
                      imgBmpSize = r.ReadInt32();
                      bmpDataPresent = true;
                      break;
                   case 3:
                      // wmf data
                      imgWmfStart = r.ReadInt32();
                      imgWmfSize = r.ReadInt32();
                      wmfDataPresent = true;
                      break;
                   default:
                       break;
             }

        }

         if (bmpDataPresent)
         {

            r.BaseStream.Seek(imgBmpStart, SeekOrigin.Begin);

            Byte[]  tempPixelData =new byte[imgBmpSize + 14];

            // indicate it is a bit map
            tempPixelData[0] = byte.Parse("H42", CultureInfo.InvariantCulture);
            tempPixelData[1] = byte.Parse("H4D", CultureInfo.InvariantCulture);

            // offBits
            tempPixelData[10] = byte.Parse("H36", CultureInfo.InvariantCulture);
            tempPixelData[11] =  byte.Parse("H4", CultureInfo.InvariantCulture);

            Byte[]  tempBuffData = new byte[imgBmpSize] ;

            tempBuffData = r.ReadBytes(imgBmpSize);
            tempBuffData.CopyTo(tempPixelData, 14);

            MemoryStream memStream  = new  MemoryStream(tempPixelData);
            Bitmap  bmp  = new Bitmap(memStream);
            Size szBmp = new System.Drawing.Size();
            szBmp.Width = picBox.Width;
            szBmp.Height = picBox.Height;
           Bitmap  bmpResize  = new Bitmap(bmp, szBmp)  ;
            picBox.Image = bmpResize;

         }

         
          // read imgWmfSize wmf data
         if (wmfDataPresent)
         {}
           
       
         Byte[] imgESentinel = {byte.Parse("E0", NumberStyles.AllowHexSpecifier),
             byte.Parse("DA", NumberStyles.AllowHexSpecifier), byte.Parse("92", NumberStyles.AllowHexSpecifier),
             byte.Parse("F8", NumberStyles.AllowHexSpecifier), byte.Parse("2B", NumberStyles.AllowHexSpecifier),
             byte.Parse("C9", NumberStyles.AllowHexSpecifier), byte.Parse("D7", NumberStyles.AllowHexSpecifier),
             byte.Parse("D7", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
             byte.Parse("A8", NumberStyles.AllowHexSpecifier), byte.Parse("35", NumberStyles.AllowHexSpecifier),
             byte.Parse("C0", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
             byte.Parse("BB", NumberStyles.AllowHexSpecifier), byte.Parse("EF", NumberStyles.AllowHexSpecifier),
             byte.Parse("D4", NumberStyles.AllowHexSpecifier)};         


         imgCSentinel = r.ReadBytes(16);

         // if image sentinel is correct
         if (imgESentinel.ToString() == imgCSentinel.ToString())
         {}
         

      }

      fs.Close();
     
         }

Hello, could you help me with your code?
I am facing an error in the following lines:
tempPixelData[0] = byte.Parse ("H42");
tempPixelData[1] = byte.Parse ("H4D");
"Input string was not in a correct format"
Could you help me please?
Thanks