Author Topic: Block Preview Icon  (Read 17133 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
Block Preview Icon
« on: January 02, 2009, 12:36:12 PM »
I am creating a block programatically, via the API, and then I want to display its PreviewIcon.  How do I do this?

After I create the block, there is no PreviewIcon.  I can run the BLOCKICON command, and then there's a PreviewIcon.  But how do I do this via the API, so I can display a preview of the block immediately after I create it?

Spike Wilbury

  • Guest
Re: Block Preview Icon
« Reply #1 on: January 02, 2009, 03:44:43 PM »
I am creating a block programatically, via the API, and then I want to display its PreviewIcon.  How do I do this?

After I create the block, there is no PreviewIcon.  I can run the BLOCKICON command, and then there's a PreviewIcon.  But how do I do this via the API, so I can display a preview of the block immediately after I create it?

Do you mean to preview it in the Block command - little image box ?

I can get the previews there, of the blocks that are generated from my routines.

What's the code you are using or have so far?

sinc

  • Guest
Re: Block Preview Icon
« Reply #2 on: January 02, 2009, 04:39:17 PM »
I can see it there, too.

It's this:

BlockTableRecord btr;  this is my block record
btr.PreviewIcon;  this is the thing that is empty until I run the BLOCKICON command


Sorry, it's a bit difficult to extract code, as it is spread through Forms controls and the working code extends over three different subprojects.

But I'm trying to solve the same problem as in this post, from almost four years ago:

http://discussion.autodesk.com/forums/message.jspa?messageID=4907295#4907295

Hopefully there's a solution to this issue by now.

Spike Wilbury

  • Guest
Re: Block Preview Icon
« Reply #3 on: January 02, 2009, 05:44:52 PM »
I can see it there, too.

It's this:

BlockTableRecord btr;  this is my block record
btr.PreviewIcon;  this is the thing that is empty until I run the BLOCKICON command


Sorry, it's a bit difficult to extract code, as it is spread through Forms controls and the working code extends over three different subprojects.

But I'm trying to solve the same problem as in this post, from almost four years ago:

http://discussion.autodesk.com/forums/message.jspa?messageID=4907295#4907295

Hopefully there's a solution to this issue by now.

I see, I have AutoCAD 2007 and it is not implemented - the help said:

Quote
PreviewIcon (Read/write)
Type
System.Drawing.Bitmap


This method is not implemented in this release.

This method is not implemented in this release.

edit: added also this:
Quote


Up a level to AcDbBlockTableRecord         
AcDbBlockTableRecord::setPreviewIcon Function Acad::ErrorStatus

setPreviewIcon(

const PreviewIcon & previewIcon);

previewIcon Input PreviewIcon containing an array of bytes, represented in the form obtained from AcDbBlockTableRecord::getPreviewIcon().

Sets the block table record's preview icon with the array of bytes. This function is useful when copyng an icon from one block to another. To generate an icon, the BLOCKICON command or the Block dialog command should be used.
« Last Edit: January 02, 2009, 06:22:13 PM by LE »

sinc

  • Guest
Re: Block Preview Icon
« Reply #4 on: January 02, 2009, 06:27:17 PM »
That's the same thing that happens in C3D 2008.

However, you can get around it.  Instead of this:

Code: [Select]
bitmap = btr.PreviewIcon;
You have to include a reference to Autodesk.AutoCAD.Internal, and then use this:

Code: [Select]
bitmap = BlockThumbnailHelper.GetBlockThumbanail(btr.ObjectId);
(with the funky spelling - it really is spelled "GetBlockThumbanail").  But it's the same thing - there's nothing there until BLOCKICON has been run, and I still haven't been able to get it to work while my command is running.  Everything seems to go bad when I try to issue the BLOCKICON command using SendStringToExecute().
« Last Edit: January 02, 2009, 06:31:06 PM by sinc »

sinc

  • Guest
Re: Block Preview Icon
« Reply #5 on: January 02, 2009, 07:12:41 PM »
I see what's happening in my code.

I create the block, then I issue the SendStringToExecute command.  However, this command is apparently being queued.  My code then pops open a dialog box that is supposed to display the block icon, but there is no block icon.  When the user hits OK in the dialog box, the user is prompted to pick some points on-screen.  It is at this point that the Editor.SelectPoint() method is processing the BLOCKICON command as keyword input.

So I'm still at the point of wondering how to get this icon refreshed without using the BLOCKICON command?  Or how do I get the BLOCKICON command to run while another command is already active?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #6 on: January 02, 2009, 08:37:57 PM »
Sinc',
I haven't played much with 2009 and not at all with C3D,

but,

I believe the 'Internal' is not neeed in 2009
and
Have you tried Tony's SendCommand method? I don't have a link, but you could perhaps find the link on the discussion Groups.

I recall having this discussion a few years ago and _BlockIcon Command seemed the solution, not sure of recent changes though.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #7 on: January 02, 2009, 11:06:57 PM »
weird,
In AC2008 Vanilla the HasPreviewIcon is false, but the BlockInsert Dialog displays the Icon.
I assume from that : the Dialog checks/or Builds it's the preview.


Code: [Select]
        [CommandMethod("BB1")]
        static public void BuildBlock_01()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            String blockName;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                blockName = DateTime.UtcNow.ToString().Replace("/", "").Replace(":", "");

                BlockTableRecord newBlockDef = new BlockTableRecord();
                newBlockDef.Name = blockName;
                BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                blockTable.Add(newBlockDef);                                       
                tr.AddNewlyCreatedDBObject(newBlockDef, true);
                //
                Circle circle1 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10);
                Circle circle2 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 12);
                newBlockDef.AppendEntity(circle1);
                newBlockDef.AppendEntity(circle2);
                tr.AddNewlyCreatedDBObject(circle1, true);
                tr.AddNewlyCreatedDBObject(circle2, true);

                tr.Commit();

                if (newBlockDef.HasPreviewIcon == true)
                {
                    ed.WriteMessage("Block {0} has a previewicon", blockName);
                }
            }
        }






... I'll keep playing

« Last Edit: January 02, 2009, 11:57:12 PM by Kerry Brown »
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #8 on: January 02, 2009, 11:10:17 PM »
ps:
I don't usually name my blocks like that ... it just seemed the quickest way to get unique block names :)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Block Preview Icon
« Reply #9 on: January 02, 2009, 11:51:22 PM »

Sorry to go off topic but ... purple text on an orange background? Yeow my eyes.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #10 on: January 02, 2009, 11:57:52 PM »
It's taken you 5 years to notice that ?

and to be pedantic, it's BLUE on Color 31
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #11 on: January 03, 2009, 12:05:31 AM »
Wheee ..
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #12 on: January 03, 2009, 12:10:38 AM »
using Tony's CommandLine.cs

from http://www.caddzone.com/CommandLine.cs


ADDED:
If you can't see ALL the code in one pane, think about changing your display theme to Mercury in Look and Layout Preferences in your Member Profile
... If you aren't a Member yet .. register .. it's free.


Code: [Select]
/ CodeHimBelongaKwb ©  Jan2009

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;


using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

using CaddZone.ApplicationServices;
/// from http://www.caddzone.com/CommandLine.cs
///

[assembly: CommandClass(typeof(
    kdub_ACAD2008_VS2008_testing_103.TestCommands))]

namespace kdub_ACAD2008_VS2008_testing_103
{
    /// <summary>
    /// Summary description for TestCommands Class.
    /// </summary>
    public class TestCommands
    {
        public TestCommands()
        {   //
            // TODO: Add constructor logic here
            //
        }

        [CommandMethod("BB1")]
        static public void BuildBlock_01()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            String blockName;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                blockName = DateTime.UtcNow.ToString().Replace("/", "").Replace(":", "");

                BlockTableRecord newBlockDef = new BlockTableRecord();
                newBlockDef.Name = blockName;
                BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                blockTable.Add(newBlockDef);                                       
                tr.AddNewlyCreatedDBObject(newBlockDef, true);
                //
                Circle circle1 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10);
                Circle circle2 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 12);
                newBlockDef.AppendEntity(circle1);
                newBlockDef.AppendEntity(circle2);
                tr.AddNewlyCreatedDBObject(circle1, true);
                tr.AddNewlyCreatedDBObject(circle2, true);

                tr.Commit();

                CommandLine.Command("BlockIcon", blockName);

                if (newBlockDef.HasPreviewIcon == true)
                {
                    ed.WriteMessage("Block {0} has a previewicon", blockName);
                }
            }
        }
}

« Last Edit: January 03, 2009, 12:39:07 AM by Kerry Brown »
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Block Preview Icon
« Reply #13 on: January 03, 2009, 12:30:18 AM »
... and with a bit of additional code ...

[edit ADDED:]
If you can't see ALL the code in one pane, think about changing your display theme to Mercury in Look and Layout Preferences in your Member Profile
... If you aren't a Member yet .. register .. it's free.

.... and you'll be able to see the picture that is posted here ..
« Last Edit: January 03, 2009, 12:43:00 AM by Kerry Brown »
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.

sinc

  • Guest
Re: Block Preview Icon
« Reply #14 on: January 03, 2009, 09:15:22 AM »
Thanks, Kerry.

Unfortunately, that solution does me no good, because of Tony's strict rules for usage.