Author Topic: Basic Block Manager  (Read 8137 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Basic Block Manager
« on: October 13, 2010, 08:26:01 AM »
This is basically embarrassing to post compared to Daniel's My Block Manager

Hopefully this could be a start for anyone who would like to improve it and post the improvements.

But it gives the basic idea of creating a tool palette with a ListView for inserting blocks using .NET.

I threw this together real quick and since I am having problems with my computer I could not really test it or did not spend time making it very useful.

This is what you get for not planning out the solution and sitting down and just start coding.

You can use the current file or an external file.
You can use the different views shown in the pic of the context menu.
Double click on the image then select the insertion point to insert the block
It must be the current drawing to produce images for blocks that do not have one. Once produced save drawing and the image will be saved with the drawing.
If you already have produced images for blocks you must close the palette and run the command "BasicBlockManagerShow" (just type "Basi" then Tab)
You can group them by Letters of the Alphabet
If you created drawings with a vertical like MEP you might want to filter out blocks that start with "Aec"



  ****************Edited************
I added the projects for C# and VB


« Last Edit: October 13, 2010, 10:20:20 AM by Jeff H »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Basic Block Manager
« Reply #1 on: October 13, 2010, 08:30:02 AM »
C#

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.Runtime.InteropServices;
namespace HpadCadBasicBlockManager
{
public partial class BasicBlockMangerPalette : UserControl
{
private bool viewGroups = false;
private static string dwgFileName = null;

public BasicBlockMangerPalette()
{
InitializeComponent();
}
private void FillListView()
{
this.lvBlocks.Items.Clear();
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
foreach (ObjectId objID in bt)
{
BlockTableRecord btr = objID.GetObject(OpenMode.ForRead) as BlockTableRecord;
if (!(btr.IsLayout))
{
string blkName = btr.Name;
Bitmap blkThumbnail = btr.PreviewIcon as Bitmap;
                        if (blkThumbnail == null)
                        {
                            using (CreateBlockIcon cbi = new CreateBlockIcon(blkName))
                            {
                                blkThumbnail = btr.PreviewIcon as Bitmap;
                            }
                        }
if (blkThumbnail == null)
{                           
AddListViewItem(blkName);
}
else
{
AddBlockImageToList(blkName, blkThumbnail);
AddListViewItem(blkName, true);
}
}
}// End foreach
trx.Commit();
}// End trx
}// End FillListView

private void FillListView(string fileName)
{
this.lvBlocks.Items.Clear();
Database db = new Database(false, true) as Database;
db.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, true, null);
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
foreach (ObjectId objID in bt)
{
BlockTableRecord btr = objID.GetObject(OpenMode.ForRead) as BlockTableRecord;
if (!(btr.IsLayout))
{
string blkName = btr.Name;
Bitmap blkThumbnail = btr.PreviewIcon as Bitmap;
                        if (blkThumbnail == null)
                        {
                            using (CreateBlockIcon cbi = new CreateBlockIcon(blkName))
                            {
                                blkThumbnail = btr.PreviewIcon as Bitmap;
                            }
                        }
if (blkThumbnail == null)
{
AddListViewItem(blkName);
}
else
{
AddBlockImageToList(blkName, blkThumbnail);
AddListViewItem(blkName, true);
}
}
}// End foreach
trx.Commit();
}// End trx
}// End FillListView

private void AddBlockImageToList(string blkName,Bitmap blkThumbnail)
{
if (!(this.BlockLargeImage.Images.ContainsKey(blkName)))
{
this.BlockLargeImage.Images.Add(blkName, blkThumbnail);
this.BlockSmallImage.Images.Add(blkName, blkThumbnail);
}
}// End AddBlockImageToList

private void AddListViewItem(string blkName,bool blkThumbnailExists)
{
ListViewItem lvi = new ListViewItem(blkName, blkName) as ListViewItem;
lvi.ToolTipText = blkName;
this.lvBlocks.Items.Add(lvi);

}// End AddListViewItem

private void AddListViewItem(string blkName)
{
ListViewItem lvi = new ListViewItem(blkName) as ListViewItem;
lvi.ToolTipText = blkName;
this.lvBlocks.Items.Add(lvi);
}// End AddListViewItem
private void SetGroups(int column)
{
lvBlocks.Groups.Clear();
List<string> groups = new List<string>();
foreach (ListViewItem item in lvBlocks.Items)
{
   string groupName = item.Text.Substring(0, 1).ToUpper();

   if (groups.Contains(groupName))
   {
  item.Group = lvBlocks.Groups[groupName];
   }
   else
   {
  groups.Add(groupName);
  item.Group = lvBlocks.Groups.Add(groupName, groupName);
  }
}
}
#region "Context Menu Code"       
        private void BlocksContextMenu_Opening(object sender, CancelEventArgs e)
        {
            this.LargeIconToolStripMenuItem.Checked = false;
            this.DetailToolStripMenuItem.Checked = false;
            this.ListViewToolStripMenuItem.Checked = false;
            this.SmallIconToolStripMenuItem.Checked = false;
            this.TileViewToolStripMenuItem.Checked = false;
            this.useCurrentFileToolStripMenuItem.Checked = false;
            this.ChooseFileToolStripMenuItem.Checked = false;
            switch (this.lvBlocks.View)
            {
                case View.LargeIcon:
                    this.LargeIconToolStripMenuItem.Checked = true;
                    break;
                case View.Details:
                    this.DetailToolStripMenuItem.Checked = true;
                    break;
                case View.List:
                    this.ListViewToolStripMenuItem.Checked = true;
                    break;
                case View.SmallIcon:
                    this.SmallIconToolStripMenuItem.Checked = true;
                    break;
                case View.Tile:
                    this.TileViewToolStripMenuItem.Checked = true;
                    break;
            }
            ShowGroupsToolStripMenuItem.Checked = viewGroups;
            if (dwgFileName == null)
            {
                this.useCurrentFileToolStripMenuItem.Checked = true;
            }
            else
            {
                this.ChooseFileToolStripMenuItem.Checked = true;
            }
        }// End BlocksContextMenu_Opening

private void LargeIconToolStripMenuItem_Click(Object sender, EventArgs e)
{
this.lvBlocks.View = View.LargeIcon;
}
private void SmallIconToolStripMenuItem_Click(Object sender, EventArgs e)
{
this.lvBlocks.View = View.SmallIcon;
}
private void DetailToolStripMenuItem_Click(Object sender, EventArgs e)
{
this.lvBlocks.View = View.Details;
}
private void ListViewToolStripMenuItem_Click(Object sender, EventArgs e)
{
this.lvBlocks.View = View.List;
}

private void TileViewToolStripMenuItem_Click(Object sender, EventArgs e)
{
this.lvBlocks.View = View.Tile;
}
private void ShowGroupsToolStripMenuItem_Click(Object sender, EventArgs e)
{
viewGroups = (!(viewGroups));
lvBlocks.ShowGroups = viewGroups;
ShowGroupsToolStripMenuItem.Checked = !ShowGroupsToolStripMenuItem.Checked;
SetGroups(0);
}
   
private void ChooseFileToolStripMenuItem_Click(object sender, EventArgs e)
{
OFD.Filter = "Block Files|*.dwg;*.dwt";
OFD.Title = "Select Block File";
OFD.Multiselect = false;
OFD.ShowHelp = true;
OFD.CheckPathExists = true;
OFD.CheckFileExists = true;
OFD.FilterIndex = 1;
try
{
if (OFD.ShowDialog() == DialogResult.OK)
{                   
dwgFileName = OFD.FileName;
FillListView(OFD.FileName);
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}

}
private void useCurrentFileToolStripMenuItem_Click(object sender, EventArgs e)
{
dwgFileName = null;
FillListView();
}
#endregion

private void lvBlocks_DoubleClick(object sender, EventArgs e)
{
string blk = lvBlocks.FocusedItem.Text;
            if (dwgFileName == null)
            {
                InsertBlock(blk);
            }
            else
            {
                InsertBlock(blk, dwgFileName);
            }

}
        private void InsertBlock(string blkName)
        {           
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            using (DocumentLock docloc = doc.LockDocument())
            using (Transaction trx = db.TransactionManager.StartTransaction())           
            {
                BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                BlockTableRecord currBtr = db.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;
                if (!(bt.Has(blkName)))
                {
                    return;
                }
                ObjectId btrId = bt[blkName].GetObject(OpenMode.ForRead).ObjectId;
                PromptPointOptions ppo = new PromptPointOptions("/nSelect Insertion Point: ");
                PromptPointResult ppr = ed.GetPoint(ppo);
                if (ppr.Status == PromptStatus.OK)
                {
                    Point3d insertPnt = ppr.Value;
                    currBtr.UpgradeOpen();
                    BlockReference bref = new BlockReference(insertPnt, btrId);
                    currBtr.AppendEntity(bref);
                    trx.AddNewlyCreatedDBObject(bref, true);
                }
                trx.Commit();
            }
        }
        private void InsertBlock(string blkName, string fileName)
        {
            Database extDb = new Database(false, true) as Database;
extDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, true, "");
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            using (DocumentLock docloc = doc.LockDocument())
            using (Transaction trx = db.TransactionManager.StartTransaction())
            using (Transaction extTrx = extDb.TransactionManager.StartTransaction())
            {               
                BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
             
                BlockTableRecord currBtr = db.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;
                if (!(bt.Has(blkName)))
                {
                    BlockTable extBt = extDb.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;                   
                    IdMapping map = new IdMapping();
                    ObjectIdCollection objIdColl = new ObjectIdCollection();
                    try
                    {
                        objIdColl.Add(extBt[blkName]);
                    }
                    catch
                    {
                        trx.Commit();
                        return;
                    }                   
                    db.WblockCloneObjects(objIdColl, bt.ObjectId, map, DuplicateRecordCloning.Replace, false);
                   
                }               
                      ObjectId btrId = bt[blkName].GetObject(OpenMode.ForRead).ObjectId;
               
                PromptPointOptions ppo = new PromptPointOptions("/nSelect Insertion Point: ");
                PromptPointResult ppr = ed.GetPoint(ppo);
                if (ppr.Status == PromptStatus.OK)
                {
                    Point3d insertPnt = ppr.Value;
                    currBtr.UpgradeOpen();
                    BlockReference bref = new BlockReference(insertPnt,btrId);
                    currBtr.AppendEntity(bref);
                    trx.AddNewlyCreatedDBObject(bref,true);
                }
                trx.Commit();
            }


        }
private void BasicBlockMangerPalette_Load(object sender, EventArgs e)
{
this.lvBlocks.ContextMenuStrip = BlocksContextMenu;
this.lvBlocks.LargeImageList = BlockLargeImage;
this.lvBlocks.SmallImageList = BlockSmallImage;
FillListView();
this.lvBlocks.ShowGroups = viewGroups;
}    
}
    public class CreateBlockIcon : IDisposable
    {
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        private static extern int acedCommand(int type1, string command, int type2, string blockName, int end);

        public CreateBlockIcon(string blkname)
        {
            acedCommand(5005, "BLOCKICON", 5005, blkname, 5000);
        }

        #region IDisposable Members

        public void Dispose()
        {
           
        }

        #endregion
    }

}







Jeff H

  • Needs a day job
  • Posts: 6150
Re: Basic Block Manager
« Reply #2 on: October 13, 2010, 08:30:43 AM »
VB
Code: [Select]
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Interop.Common
Imports System.Runtime.InteropServices


Public Class BasicBlockMangerPalette
    Private viewGroups As Boolean = False
    Private Shared dwgFileName As String = Nothing
    Private Sub FillListView()
        Me.lvBlocks.Items.Clear()
        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Using trx As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
            For Each objID As ObjectId In bt
                Dim btr As BlockTableRecord = TryCast(objID.GetObject(OpenMode.ForRead), BlockTableRecord)
                If Not (btr.IsLayout) Then
                    Dim blkName As String = btr.Name
                    Dim blkThumbnail As Bitmap = TryCast(btr.PreviewIcon, Bitmap)
                    If blkThumbnail Is Nothing Then
                        Dim cbi As New CreateBlockIcon(blkName)
                        blkThumbnail = TryCast(btr.PreviewIcon, Bitmap)
                        cbi = Nothing
                    End If

                    If blkThumbnail Is Nothing Then
                        AddListViewItem(blkName)
                    Else
                        AddBlockImageToList(blkName, blkThumbnail)
                        AddListViewItem(blkName, True)
                    End If
                End If
            Next
            ' End foreach
            trx.Commit()
        End Using
        ' End trx
    End Sub
    ' End FillListView
    Private Sub FillListView(ByVal fileName As String)
        Me.lvBlocks.Items.Clear()
        Dim db As Database = TryCast(New Database(False, True), Database)
        db.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, True, Nothing)
        Using trx As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = (db.BlockTableId.GetObject(OpenMode.ForRead))
            For Each objID As ObjectId In bt
                Dim btr As BlockTableRecord = TryCast(objID.GetObject(OpenMode.ForRead), BlockTableRecord)
                If Not (btr.IsLayout) Then
                    Dim blkName As String = btr.Name
                    Dim blkThumbnail As Bitmap = TryCast(btr.PreviewIcon, Bitmap)
                    If blkThumbnail Is Nothing Then
                        Dim cbi As New CreateBlockIcon(blkName)
                        blkThumbnail = TryCast(btr.PreviewIcon, Bitmap)
                        cbi = Nothing
                    End If
                    If blkThumbnail Is Nothing Then
                        AddListViewItem(blkName)
                    Else
                        AddBlockImageToList(blkName, blkThumbnail)
                        AddListViewItem(blkName, True)
                    End If
                End If
            Next
            ' End foreach
            trx.Commit()
        End Using
        ' End trx
    End Sub
    ' End FillListView
    Private Sub AddBlockImageToList(ByVal blkName As String, ByVal blkThumbnail As Bitmap)
        If Not (Me.BlockLargeImage.Images.ContainsKey(blkName)) Then
            Me.BlockLargeImage.Images.Add(blkName, blkThumbnail)
            Me.BlockSmallImage.Images.Add(blkName, blkThumbnail)
        End If
    End Sub
    ' End AddBlockImageToList
    Private Sub AddListViewItem(ByVal blkName As String, ByVal blkThumbnailExists As Boolean)
        Dim lvi As ListViewItem = TryCast(New ListViewItem(blkName, blkName), ListViewItem)
        lvi.ToolTipText = blkName
        Me.lvBlocks.Items.Add(lvi)

    End Sub
    ' End AddListViewItem
    Private Sub AddListViewItem(ByVal blkName As String)
        Dim lvi As ListViewItem = TryCast(New ListViewItem(blkName), ListViewItem)
        lvi.ToolTipText = blkName
        Me.lvBlocks.Items.Add(lvi)
    End Sub
    ' End AddListViewItem
    Private Sub SetGroups(ByVal column As Integer)
        lvBlocks.Groups.Clear()
        Dim groups As New List(Of String)()
        For Each item As ListViewItem In lvBlocks.Items
            Dim groupName As String = item.Text.Substring(0, 1).ToUpper()

            If groups.Contains(groupName) Then
                item.Group = lvBlocks.Groups(groupName)
            Else
                groups.Add(groupName)
                item.Group = lvBlocks.Groups.Add(groupName, groupName)
            End If
        Next
    End Sub
#Region "Context Menu Code"
    Private Sub BlocksContextMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles BlocksContextMenu.Opening
        Me.LargeIconToolStripMenuItem.Checked = False
        Me.DetailToolStripMenuItem.Checked = False
        Me.ListViewToolStripMenuItem.Checked = False
        Me.SmallIconToolStripMenuItem.Checked = False
        Me.TileViewToolStripMenuItem.Checked = False
        Me.useCurrentFileToolStripMenuItem.Checked = False
        Me.ChooseFileToolStripMenuItem.Checked = False
        Select Case Me.lvBlocks.View
            Case View.LargeIcon
                Me.LargeIconToolStripMenuItem.Checked = True
                Exit Select
            Case View.Details
                Me.DetailToolStripMenuItem.Checked = True
                Exit Select
            Case View.List
                Me.ListViewToolStripMenuItem.Checked = True
                Exit Select
            Case View.SmallIcon
                Me.SmallIconToolStripMenuItem.Checked = True
                Exit Select
            Case View.Tile
                Me.TileViewToolStripMenuItem.Checked = True
                Exit Select
        End Select
        ShowGroupsToolStripMenuItem.Checked = viewGroups
        If dwgFileName Is Nothing Then
            Me.useCurrentFileToolStripMenuItem.Checked = True
        Else
            Me.ChooseFileToolStripMenuItem.Checked = True
        End If
    End Sub
    ' End BlocksContextMenu_Opening
    Private Sub LargeIconToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LargeIconToolStripMenuItem.Click
        Me.lvBlocks.View = View.LargeIcon
    End Sub

    Private Sub SmallIconToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmallIconToolStripMenuItem.Click
        Me.lvBlocks.View = View.SmallIcon
    End Sub

    Private Sub DetailToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DetailToolStripMenuItem.Click
        Me.lvBlocks.View = View.Details
    End Sub

    Private Sub ListViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListViewToolStripMenuItem.Click
        Me.lvBlocks.View = View.List
    End Sub

    Private Sub TileViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileViewToolStripMenuItem.Click
        Me.lvBlocks.View = View.Tile
    End Sub

    Private Sub ShowGroupsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowGroupsToolStripMenuItem.Click
        viewGroups = (Not (viewGroups))
        lvBlocks.ShowGroups = viewGroups
        ShowGroupsToolStripMenuItem.Checked = Not ShowGroupsToolStripMenuItem.Checked
        SetGroups(0)
    End Sub

    Private Sub ChooseFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChooseFileToolStripMenuItem.Click
        OFD.Filter = "Block Files|*.dwg;*.dwt"
        OFD.Title = "Select Block File"
        OFD.Multiselect = False
        OFD.ShowHelp = True
        OFD.CheckPathExists = True
        OFD.CheckFileExists = True
        OFD.FilterIndex = 1
        Try
            If OFD.ShowDialog() = DialogResult.OK Then
                dwgFileName = OFD.FileName
                FillListView(OFD.FileName)
            End If
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub useCurrentFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles useCurrentFileToolStripMenuItem.Click
        dwgFileName = Nothing
        FillListView()
    End Sub
 
#End Region

   
    Private Sub InsertBlock(ByVal blkName As String)
        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Using docloc As DocumentLock = doc.LockDocument()
            Using trx As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
                Dim currBtr As BlockTableRecord = TryCast(db.CurrentSpaceId.GetObject(OpenMode.ForRead), BlockTableRecord)
                If Not (bt.Has(blkName)) Then
                    Return
                End If
                Dim btrId As ObjectId = bt(blkName).GetObject(OpenMode.ForRead).ObjectId
                Dim ppo As New PromptPointOptions("/nSelect Insertion Point: ")
                Dim ppr As PromptPointResult = ed.GetPoint(ppo)
                If ppr.Status = PromptStatus.OK Then
                    Dim insertPnt As Point3d = ppr.Value
                    currBtr.UpgradeOpen()
                    Dim bref As New BlockReference(insertPnt, btrId)
                    currBtr.AppendEntity(bref)
                    trx.AddNewlyCreatedDBObject(bref, True)
                End If
                trx.Commit()
            End Using
        End Using
    End Sub
    Private Sub InsertBlock(ByVal blkName As String, ByVal fileName As String)
        Dim extDb As Database = TryCast(New Database(False, True), Database)
        extDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, True, "")
        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Using docloc As DocumentLock = doc.LockDocument()
            Using trx As Transaction = db.TransactionManager.StartTransaction()
                Using extTrx As Transaction = extDb.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)

                    Dim currBtr As BlockTableRecord = TryCast(db.CurrentSpaceId.GetObject(OpenMode.ForRead), BlockTableRecord)
                    If Not (bt.Has(blkName)) Then
                        Dim extBt As BlockTable = TryCast(extDb.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
                        Dim map As New IdMapping()
                        Dim objIdColl As New ObjectIdCollection()
                        Try
                            objIdColl.Add(extBt(blkName))
                        Catch
                            trx.Commit()
                            Return
                        End Try

                        db.WblockCloneObjects(objIdColl, bt.ObjectId, map, DuplicateRecordCloning.Replace, False)
                    End If
                    Dim btrId As ObjectId = bt(blkName).GetObject(OpenMode.ForRead).ObjectId

                    Dim ppo As New PromptPointOptions("/nSelect Insertion Point: ")
                    Dim ppr As PromptPointResult = ed.GetPoint(ppo)
                    If ppr.Status = PromptStatus.OK Then
                        Dim insertPnt As Point3d = ppr.Value
                        currBtr.UpgradeOpen()
                        Dim bref As New BlockReference(insertPnt, btrId)
                        currBtr.AppendEntity(bref)
                        trx.AddNewlyCreatedDBObject(bref, True)
                    End If
                    trx.Commit()
                End Using
            End Using
        End Using


    End Sub

    Private Sub lvBlocks_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvBlocks.DoubleClick
        Dim blk As String = lvBlocks.FocusedItem.Text
        If dwgFileName Is Nothing Then
            InsertBlock(blk)
        Else
            InsertBlock(blk, dwgFileName)
        End If
    End Sub
    Private Sub BasicBlockMangerPalette_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.lvBlocks.ContextMenuStrip = BlocksContextMenu
        Me.lvBlocks.LargeImageList = BlockLargeImage
        Me.lvBlocks.SmallImageList = BlockSmallImage
        FillListView()
        Me.lvBlocks.ShowGroups = viewGroups

    End Sub

   
 
   
End Class
Public Class CreateBlockIcon
    <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
    Private Shared Function acedCommand(ByVal type1 As Integer, ByVal command As String, ByVal type2 As Integer, ByVal blockName As String, ByVal [end] As Integer) As Integer

    End Function
    Sub New(ByVal blkname As String)
        acedCommand(5005, "BLOCKICON", 5005, blkname, 5000)
    End Sub
End Class

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Basic Block Manager
« Reply #3 on: October 14, 2010, 09:03:19 AM »
Now that I have the system up and running It needs improvements
1. Dynamic blocks and Attributes
2. Jig the Block for Insert
3. A better way of producing preview Icons
4. After double click the palette needs to lose focus

This was from a minute of messing with it and I sure there are more.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Basic Block Manager
« Reply #4 on: October 14, 2010, 07:52:46 PM »
Now that I have the system up and running It needs improvements
1. Dynamic blocks and Attributes
2. Jig the Block for Insert
3. A better way of producing preview Icons
4. After double click the palette needs to lose focus

This was from a minute of messing with it and I sure there are more.


Nicely done. Thanks for sharing.
I'll attach a class I use for jigging. It was put together from various approaches I've seen.
Sorry it isn't documented better. The arguments to the methods are strings because I designed it to be usable from VBA. (COM)

As far as getting the focus on the drawing editor from the palette goes, that's a problem I'm still living with.
I think there are solutions that work with earlier versions but I'm coding for 2011 and I'm stuck.

I've been working on a block manager too. . . . for about 10 years now.
Actually our company has been using it for about 8 years and it's a big time saver for us. I would encourage you to keep at it.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Basic Block Manager
« Reply #5 on: October 14, 2010, 08:17:32 PM »
Thanks
this week is mid terms and I have not spent much time with it
But thanks alot for the jig implementation

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: Basic Block Manager
« Reply #6 on: October 15, 2010, 05:27:07 AM »
Nice!  8-)