TheSwamp

Code Red => .NET => Topic started by: DBARANAS on July 18, 2006, 10:48:07 PM

Title: Palette Problem
Post by: DBARANAS on July 18, 2006, 10:48:07 PM
Using code translated from MickD's simple palette app I made lots of palettes based on the following:

All of the user controls are thin strips 1240w x 32h meant to go at the top of the app. When they open they eat up the whole screen and have to be minimized then redocked and resized.

Has anybody been able to get palettes to work properly when docking to the top or bottom?

This would be so nice to have as so much screen space gets saved this way.

regards, Dave

    <CommandMethod("cmd")> Public Sub createPalettes()

        createPaletteCommand()

    End Sub
    Public Sub createPaletteCommand()

        If paletteCommand Is Nothing Then
            paletteCommand = New Autodesk.AutoCAD.Windows.PaletteSet("Command Palette")
            paletteCommand.Style = PaletteSetStyles.Snappable Or  PaletteSetStyles.ShowAutoHideButton
            paletteCommand.Opacity = 60
            paletteCommand.Size = New System.Drawing.Size(1240, 32)
            paletteCommand.MinimumSize = New System.Drawing.Size(1240, 32)
            'paletteCommand.WindowState = FormWindowState.Normal
            paletteCommand.Add("Commands", New commands())
            paletteCommand.Dock = Autodesk.AutoCAD.Windows.DockSides.Top
            'You may or may not need the below code for list/combo boxes to retain focus.
            paletteCommand.KeepFocus = True
            paletteCommand.Visible = True
        Else
            paletteCommand.Visible = True
        End If

    End Sub
Title: Re: Palette Problem
Post by: MickD on July 18, 2006, 11:23:52 PM
What size is your user control? try setting this to suit and set it to 'locked'.
Otherwise I'm not sure, there may be some base methods that need to be overridden.
hth,
Mick.
Title: Re: Palette Problem
Post by: DBARANAS on July 18, 2006, 11:58:45 PM
The User Control is set to 1240 x 32. I locked it but it still does the same thing

When I minimize it it looks like 1280x1024, then when I redock it to the top it now knows that it is only 32 pixels high and does what it's supposed to.

It's like something is short circuited inside between width and height when the palette first loads

Dave

Title: Re: Palette Problem
Post by: MickD on July 19, 2006, 12:17:44 AM
Ah ok, I have noticed that myself and I don't think it can be changed easily but I haven't really tried too hard either  :roll:

I have my docksides set to none and it loads up docked and sized properly after docking in the first session after loading (or last good session) so acad must be saving its state some where.
Title: Re: Palette Problem
Post by: DBARANAS on July 19, 2006, 12:19:58 AM
It seems the problem is that the palette always docks to the left no matter what side you set it to when it loads

Dave
Title: Re: Palette Problem
Post by: MickD on July 19, 2006, 01:06:58 AM
I know this probably won't help you with what you want to do but are you using this like a tool bar?
If you are I've noticed some editor <-> palette focus issues which crop up such as if you still have your mouse over the palette your code doesn't get executed! This mainly happens with methods that don't require user action from the editor.
For instance, I have some view setting buttons with default views of 3d models, when I pick to set the new view it seemed to take a long time and then I noticed what was happening. The user still had the mouse over the button waiting for the screen to update :)
This probably can be fixed but toolbars take up less room anyway (and I don't have the spare time lately :) )

So, I'll be moving all of my simple methods to commands and toolbars and save the palette for list boxes and larger controls which are better suited to side docking anyway.
Cheers,
Mick.
Title: Re: Palette Problem
Post by: DBARANAS on July 19, 2006, 03:30:50 AM
Yes that's pretty much what I am trying to do. I got about 20 of these palette strips and they contain textboxes, cmdButtons, cboBoxes, etc

There should never have to be more than 3 or 4 displayed at any given time. I am trying to make them intuitive and autoswitch on and go away when not needed.

I got it working now and can autoload the main "Command" palette and have it dock to the top.
It remembers the palette location for next time wherever you set it as well. But only if I use a Guid and the addHandlers

I found an example over in acad.net from Mike Tuersley I distilled down and mixed with your sample to get this:

    Public paletteCommands As Autodesk.AutoCAD.Windows.PaletteSet
    Public paletteCommand As commands

    Public Class Class1
        Implements IExtensionApplication

        Public Sub Initialize() Implements IExtensionApplication.Initialize

            Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.RemoveDefaultPane(DefaultPane.All)

            StartInterface()

        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate

        End Sub

    End Class

    Public Sub StartInterface()

        If paletteCommands Is Nothing Then

            paletteCommands = New Autodesk.AutoCAD.Windows.PaletteSet("acadToolPalette", New Guid("63B8DB5B-10E4-4924-B8A2-A9CF9158E4F6"))

            AddHandler paletteCommands.Load, AddressOf ps_Load 'add the events
            AddHandler paletteCommands.Save, AddressOf ps_Save

            paletteCommands.Style = PaletteSetStyles.ShowPropertiesMenu Or PaletteSetStyles.ShowAutoHideButton Or PaletteSetStyles.ShowCloseButton
            paletteCommands.MinimumSize = New System.Drawing.Size(1240, 36)
            paletteCommands.Dock = Autodesk.AutoCAD.Windows.DockSides.Top

            paletteCommand = New commands
            paletteCommands.Add("Commands", paletteCommand)

        End If
        paletteCommands.Visible = True

    End Sub

    'skeleton construct to configuration settings
    'refer to acadDefaults example project
    Private Sub ps_Load(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.Windows.PalettePersistEventArgs)
        '
        Dim a As Double = CType(e.ConfigurationSection.ReadProperty("whatever", 22.3), Double)

    End Sub

    Private Sub ps_Save(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.Windows.PalettePersistEventArgs)
        '
        e.ConfigurationSection.WriteProperty("whatever", 32.3)

    End Sub

Next I will see if I can get all the palettes to work together
Title: Re: Palette Problem
Post by: DBARANAS on July 19, 2006, 07:08:36 AM
I got the palettes working and only needed this code:

        palCommands = New Autodesk.AutoCAD.Windows.PaletteSet("Commands", New Guid("63B8DB5B-10E4-4924-B8A2-A9CF9158E4F6"))
        palCommands.Style = PaletteSetStyles.ShowPropertiesMenu
        palCommand = New commands
        palCommands.Add("Commands", palCommand)
        palCommands.KeepFocus = True
        palCommands.Visible = True

There is no need to specify the docking or add the handlers. the palettes just remember wherever they were set to the next time the drawing is opened...just like normal acad.

But I find out the enter method does not work or the keydown method either. I can type normal and enter text but can't trap the enter key. This one is just too much!


Title: Re: Palette Problem
Post by: DBARANAS on July 20, 2006, 09:40:06 PM
Palettes all working very nice including comboboxes tha drop off the palette.

The text boxes are a strange creature .......this works

    Private Sub txtLength_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLength.KeyDown

        If e.KeyData = Keys.Right Then
          'Stuff
        End If

    End Sub

but this ......does not

        If e.KeyData = Keys.Enter Then

or this .....either

        If e.KeyData = Keys.Return Then

The keydown method does not get triggered by those....using the right arrow key is a way to make it work but it is weird that the proper keys do not work.

This happens only with textboxes inside palettes. Has anyone ever seen this happen??

regards,

Dave
Title: Re: Palette Problem
Post by: MickD on July 20, 2006, 09:58:16 PM
Try using 'e.KeyCode' to get your key value.
Title: Re: Palette Problem
Post by: DBARANAS on July 20, 2006, 11:40:22 PM
Thanks Mick

I already tried it before and no luck.

I ended up with key.value after sailing and trying the sea of texbox events.

key.code works the same way as key.data

In fact I tried every way to make it work for me trying to capture a "key.enter" event and when I hit "enter" it is as like I never did anything.

I went through key.*.* and they all work except key.enter or key.return

Thanks for always helping me Mick.

I could come up with "because this app is so special you have to hit the right arrow key instead of the enter key" "every one knows the right arrow key is way faster...aren't you glad I shared that with you????"

As always...you get something almost figured out and hit a stupid wall. This should be my best signature!!!

Everyone in the swamp please forgive this unmanaged uncontrolled exception.....CLR cops on the way!

" You exception is now unmanaged...danger....danger...step back from the unmanaged zone!!!

I am going to get some sleep......programming is now my drug of choice and I am now brain dead
Title: Re: Palette Problem
Post by: MickD on July 21, 2006, 12:20:33 AM
Have you tried the keyPress or KeyUp events?
Title: Re: Palette Problem
Post by: DBARANAS on July 21, 2006, 08:17:34 PM
Yes I tried those as well...

This is for all swampers so we all know why I went off....

I got a little frustrated last night trying every textbox method to see if I could get around this problem,, and ranted off a bit....but the batteries are full again and I am back for more.

I spent 3 years working almost every day non stop to make a program that could design a building like ADT but then tear the model down and load it onto a truck based on assembly order for the crane operator so he could watch how every peice gets loaded off looking at his pocket PC.

I had all of this already figured out in VBA but smashed into the memory leak wall. If you try to make an app in VBA you will see what I mean. I am not talking about a few macros but 30,000+ lines of code.

So far I have 70% of that code working in .Net and did it in 25 days.

My goal is to learn things the .Net way and throw back my pain and how I overcame it showing solutions.

You will not see yet where I have answered a problem yet .....but I explain where I mess up. And that must be of some help. I never take something and run away...even if it was an easy thing I try to explain in the context of the problem why I asked the question in the 1st place.

I think this swamp is the only hope for those working in acad.net....Thanks to everyone here for putting up with me

Dave





Title: Re: Palette Problem
Post by: MickD on July 25, 2006, 03:09:48 AM
Hey Dave, give something like this a go -

Code: [Select]
protected override void OnKeyDown(KeyEventArgs kea)
{
base.OnKeyDown(kea); // note call to base class!
switch(kea.KeyCode)
{
case Keys.Enter:
//do sumtin:
break;
}
}
Title: Re: Palette Problem
Post by: MickD on July 25, 2006, 04:33:38 AM
Nope, that don't work neither :(
Title: Re: Palette Problem
Post by: DBARANAS on August 16, 2006, 11:07:33 PM
I went to datagridviews and solved the problem. The ENTER key now works. I also struggled on how to show a grid by rows instead of collumns.

This is valuable if you want to display items in a row instead of scrolling across lots of collumns like the datadridview typically works. Everything on the forms is like this now..I had 400 controls and I replaced them all by putting them into 10 grids.

I searched for 2 weeks to find how to do this with a grid and then had to figure it out. I think this is a nice way to display things in a CAD app...here is what I did....

    Public Sub DVGTest()

        With dgvDebugList  'A datagridview on a form

            .ColumnCount = 11
            .RowCount = 100

            For Each column As DataGridViewColumn In dgvDebugList.Columns
                Select Case column.Index
                    Case 0
                        column.HeaderCell.Value = column.Index & "DVG Test"
                        column.SortMode = DataGridViewColumnSortMode.NotSortable
                End Select
            Next

            For Each row As DataGridViewRow In dgvDebugList.Rows
                Dim chk As DataGridViewCheckBoxCell = New DataGridViewCheckBoxCell()
                Dim txt As DataGridViewTextBoxCell = New DataGridViewTextBoxCell()
                Select Case row.Index
                    Case 0
                        row.HeaderCell.Value = "allowMakeBnd"
                        row.Cells(0) = txt : txt.Value = SetupItems.allowMakeBnd
                    Case 1
                        row.HeaderCell.Value = "bAutotests"
                        row.Cells(0) = chk : chk.Value = SetupItems.bAutotests
                    Case 2
                        row.HeaderCell.Value = "bBuildPreview"
                        row.Cells(0) = chk : chk.Value = SetupItems.bBuildPreview
                    Case 3
                        row.HeaderCell.Value = "bColor"
                        row.Cells(0) = chk : chk.Value = SetupItems.bColor
                    Case 4
                        row.HeaderCell.Value = "bDimension"
                End Select
            Next

            Me.Controls.Add(dgvDebugList)

        End With

    End Sub
Title: Re: Palette Problem
Post by: MickD on August 16, 2006, 11:48:08 PM
That looks good Dave, so I'd imagine it has scroll bars bottom and side?
Fair bit of data to deall with there also 1000 cells!
Title: Re: Palette Problem
Post by: DBARANAS on August 17, 2006, 12:17:33 AM
Hi Mick,

yes it has all that!

I am very proud that I googled my brains out, never found an answer, then did it the hard way and came up with something perfect for me. Put this into a tool palette and I am well on my way to making a professional CAD app.

BTW I gave up on that idea of putting up tool palettes horizontally. I make tool pallettes on the left that I switch is the best way to make a GUI for CAD

I will post a better example if anyone wants it.
Title: Re: Palette Problem
Post by: DBARANAS on August 17, 2006, 12:26:46 AM
Correction.

Although tha classes may have over 1000 properties, lots of them are array() properties.

They each get their own collumn, so the size rarely exceeds a rowcount of 100.

BTW that was my debug grid.

I use a combo to switch grids and it does the work with hardly a refresh delay

It works really well switching classes into grids.

The only reason I even do thiis is to trap errors....in VBA this was vet simple
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 12:30:00 AM
Nice job, very slick!
Title: Re: Palette Problem
Post by: DBARANAS on August 17, 2006, 12:37:29 AM
Thanks Mick!

it is way too $$% Slick. I wish my programming ability was as slick as my ideas

90% of my efforts are figuring out a way to make code do what I want.

That one was a bitch....But I had to have it. Now that I have it everything else falls into place.

Dave

Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 12:49:19 AM
Quote
90% of my efforts are figuring out a way to make code do what I want.

If it was easy, everyone would be doing it :D
Title: Re: Palette Problem
Post by: DBARANAS on August 17, 2006, 12:56:43 AM
Touche!!

You got a good point.

Otherwise I would "wind up working at a gas station" - Frank Zappa 1976




Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 02:03:31 AM
Very slick Dave - nice work. Did you consider using a "propertygrid"? I use these for configuration on a dialog (if it requires it) fired from a "settings" button. The beauty of them is that you can design a class, which needs certain attributes and tell the grid to use it and it will display it. It's also easy to serialise as well. I should have thought of this before and mentioned it earlier.

If any one wants to see an example, let me know.

Cheers,
Glenn.
Title: Re: Palette Problem
Post by: Draftek on August 17, 2006, 07:39:11 AM
Count 1.

I'd like to see it.
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 07:19:04 PM
Here you go - ponder the attached. It's fairly straighforward.
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 08:20:31 PM
The concept is quite good and easy to implement but I had some trouble using autocad object properties with the prop's grid in that it crashed when trying to update them. Properties of user defined classes are a snap though and the grid attributes save quite a bit of work.

I probably could have explored the problem further but put it in the too hard basket for now :)
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 09:03:55 PM
I'm quite liking them actually, for the exact same reasons you just stated there Mick.
The property grid would be ideal to throw on a palette me thinks...
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 09:04:59 PM
Got an example of how you were using it with AutoCAD objects handy Mick?
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 09:25:06 PM
I'll see if I kept the code, if not I'll knock something up, brb.
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 10:17:11 PM
Ok, this is an unorthodox way of setting entity prop's but I needed it to get and set some xdata but this simple app shows what I was trying to do.

The prop's dialog code and a class to work with:
Code: [Select]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace CsMgdAcad2
{
// My class for testing, we have to get and set the prop's
// ourselves as these ents may not have .net attributes
// available.
public class MyEnt
{
private Entity m_ent;
private Autodesk.AutoCAD.Colors.Color m_colour;

public MyEnt(ref Entity ent) // takes an entity reference
{
m_ent = ent; // get some info for the prop's grid:
m_colour = ent.Color; // we'll use the colorindex prop.
}

// this is the logical place to change the values
// from the props grid while dialog still open(maybe not ?)
~MyEnt()
{
m_ent.Color = m_colour; // set the new colour:
}

// set some prop's for the prop's grid:
[CategoryAttribute("Object Data"),
DescriptionAttribute("Name of Section")]
public Autodesk.AutoCAD.Colors.Color Colour
{
get
{
return m_colour;
}
set
{
m_colour = value;
}
}
}
/// <summary>
/// Summary description for Props.
/// </summary>
public class Props : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Props()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.SuspendLayout();
//
// propertyGrid1
//
this.propertyGrid1.CommandsVisibleIfAvailable = true;
this.propertyGrid1.LargeButtons = false;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
this.propertyGrid1.Location = new System.Drawing.Point(16, 8);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(256, 400);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.Text = "propertyGrid1";
this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
//
// Props
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 414);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.propertyGrid1});
this.Name = "Props";
this.Text = "Props";
this.Load += new System.EventHandler(this.Props_Load);
this.ResumeLayout(false);

}
#endregion

private void Props_Load(object sender, System.EventArgs e)
{
Database db =
HostApplicationServices.WorkingDatabase;
Editor ed =
Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument.Editor;
Transaction tr =
db.TransactionManager.StartTransaction();
MyEnt myent;
try
{

PromptEntityResult res =
ed.GetEntity("\nPick an entity to get the info:");
Entity ent =
tr.GetObject(res.ObjectId, OpenMode.ForWrite)as Entity;
if(ent != null)
{
myent = new MyEnt(ref ent);
propertyGrid1.SelectedObject = myent;
}
tr.Commit();

}
catch
{

}
finally
{
tr.Dispose();
}
}
}
}

if I try and set the colour of the ent directly in the property's set() I get a eNotOpenForWrite error and a crash!
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 10:27:14 PM
That's what I was expecting you to say Mick about the eNotOpenForWrite - have you tried opening for write whilst it is in your dialog?
It would need this as AutoCAD uses the open/close transaction mechanism...

Actually, on second look, it looks like your myEnt variable is going out of scope too early...
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 10:31:33 PM
Actually, on 3rd look :), your transaction has finished and been commited, so the object is closed.
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 10:47:35 PM
Doh!, it's always somethng obvious (to new eye's). I'll see if I can remedy it now. I may have to re-implement it into my app for updating some xdata which was the whole reasom for using it in the first place.
brb
Title: Re: Palette Problem
Post by: Glenn R on August 17, 2006, 10:54:43 PM
Mick, I don't want to have to reproduce your project to test, so can you post the zipped project so I can play...
Title: Re: Palette Problem
Post by: MickD on August 17, 2006, 11:15:47 PM
No prob's, I had made a few changes before I caught you post but the original code is still above.
The changes -
Code: [Select]
private ObjectId m_entId;
private Autodesk.AutoCAD.Colors.Color m_colour;
private Database db = HostApplicationServices.WorkingDatabase;

public MyEnt(ObjectId entId) // takes an entity ObjectId
{
m_entId = entId; // get some info for the prop's grid:
using(Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(m_entId, OpenMode.ForWrite)as Entity;
m_colour = ent.Color;
}
}

// update the ent's prop's in the destructor(?)
~MyEnt()
{
using(Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(m_entId, OpenMode.ForWrite)as Entity;
ent.Color = m_colour; // set the new colour:
}
}
Title: Re: Palette Problem
Post by: Glenn R on August 18, 2006, 12:05:51 AM
Did you get it to work Mick?
Title: Re: Palette Problem
Post by: MickD on August 18, 2006, 12:16:05 AM
Nope, I put it down after the last post, bigger fish to fry at the moment :). It wouldn't be a bad thing to implement for xdata, it can make the data look like real properties of the objects selected.
I'm just using a simple dilaog at the moment that works fine and is not confused with the proper properties dialog used by acad, i'm happy with that but others may well find a good use for this approach I'd imagine, Dave's grid may be the best answer.
Title: Re: Palette Problem
Post by: Glenn R on August 18, 2006, 12:27:01 AM
I got it to work by axing your desctructor (as in your implementation, you don't know when it will be called - maybe wrap in a using statement or dispose of it the form close down).

Good to see you went objectid's as well - that's the way I would have done it.

Cheers,
Glenn.
Title: Re: Palette Problem
Post by: MickD on August 18, 2006, 12:37:34 AM
I use id's liberally now since I've had to pass them back and forth to arx/managed and it works very well.
I thought of setting the prop's in the set() method of the MyEnt property, is that what you?
Title: Re: Palette Problem
Post by: Glenn R on August 18, 2006, 01:34:49 AM
Yep - I used objectIds for class stuff in ARX as well.

Yes, I did it in the 'set'.
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 01:37:28 AM
I have been playing with the property grid example.

I really like that you don't have to manage row and collumns...this is becoming tedious as I plug it in everywhere. I added an array and it shows all the elements and it was no more code to do that!

A good use for that grid is displaying my classes for debugging, I got 1 of my big classes running in the grid I posted, but it was 1000 boring lines of code.

I am trying to get the property grid on a form that goes on a pallette. I get the palette but not the grid. Surprizingly it pops up a separate  acad property palette.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PropertyGridTest
{
   public partial class frmProperties : Form
   {
      private AppSettings _appSettings = null;

      public frmProperties()
      {

         InitializeComponent();
         _appSettings = new AppSettings();

      }

      public frmProperties(AppSettings appSettings) : this()
      {
         propertyGrid1.SelectedObject = appSettings;
      }

      private void InitializeComponent()
      {
         this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
         this.SuspendLayout();
         //
         //propertyGrid1
         //
         this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
         this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
         this.propertyGrid1.Name = "propertyGrid1";
         this.propertyGrid1.Size = new System.Drawing.Size(252, 916);
         this.propertyGrid1.TabIndex = 1;
         //
         //frmProperties
         //
         this.ClientSize = new System.Drawing.Size(252, 916);
         this.Controls.Add(this.propertyGrid1);
         this.Name = "frmProperties";
         this.ResumeLayout(false);

      }
      private System.Windows.Forms.PropertyGrid propertyGrid1;
   }

}

Title: Re: Palette Problem
Post by: MickD on August 18, 2006, 01:45:29 AM
The best way to go is create a user control instead of a form to host the property grid and set the user control in your palette's load method.
Sing out if you need a hand.
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 02:20:07 AM
I changed it back to a user control and changed the new sub and it works.

I made a class public to fit into the app. I got lucky on this one!!

   public PropertyGridTest.frmProperties ctlProperties = new PropertyGridTest.frmProperties();
   public PropertyGridTest.AppSettings PropertyItems = new PropertyGridTest.AppSettings();

   public void createPaletteProperties()
   {

      pProperties = new Autodesk.AutoCAD.Windows.PaletteSet("Properties", new Guid("99741830-3C35-42ed-8008-B27226C9A188"));
      pProperties.Style = PaletteSetStyles.ShowCloseButton == false;
      pProperties.Style = PaletteSetStyles.ShowTabForSingle == false;
      PropertyItems = new PropertyGridTest.AppSettings();
      ctlProperties = new PropertyGridTest.frmProperties();
      pProperties.Add("Properties", ctlProperties);
      pProperties.Size = new System.Drawing.Size(260, 950);
      pProperties.Dock = Autodesk.AutoCAD.Windows.DockSides.Right;
      pProperties.KeepFocus = true;
      pProperties.Visible = false;

   }

using System.Windows.Forms;

namespace PropertyGridTest
{
   public partial class frmProperties : System.Windows.Forms.UserControl
   {
      //Inherits Form
      private AppSettings _appSettings = null;

      public frmProperties()
      {
         InitializeComponent();
         propertyGrid1.SelectedObject = PropertyItems;
      }

      private void InitializeComponent()
      {
         this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
         this.SuspendLayout();
         //
         //propertyGrid1
         //
         this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
         this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
         this.propertyGrid1.Name = "propertyGrid1";
         this.propertyGrid1.Size = new System.Drawing.Size(252, 916);
         this.propertyGrid1.TabIndex = 1;
         //
         //frmProperties
         //
         this.ClientSize = new System.Drawing.Size(252, 916);
         this.Controls.Add(this.propertyGrid1);
         this.Name = "frmProperties";
         this.ResumeLayout(false);

      }
      private System.Windows.Forms.PropertyGrid propertyGrid1;
   }

}
Title: Re: Palette Problem
Post by: MickD on August 18, 2006, 02:24:18 AM
*woot!*  :kewl:
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 02:54:42 AM
Mick

I see you were trying to use objects in a grid.

Everything I make in the models gets serialized into binary files. All the objectID's are in those files.

I can fake it and fill the grid and get the same result, because I get things from those files

 I don't know if this helps, but it is an approach I took because it was all I knew and hacked something up to get around my lack of knowledge.

Title: Re: Palette Problem
Post by: MickD on August 18, 2006, 04:47:51 AM
The main reason I need a prop's dialog is simply to view/update data (xdata in this case) stored on any particular object. This way I let autocad look after my data as well as the object's.
You could also use xrecords which have a huge potential capacity for data storage but half the data I need needs to be updated with object modifications which with the right type, xdata can do this automatically.
The other half could be serialized out but it's easier just to store it with all the other data as xdata, this allows you to copy and paste into other drawings also and the objects take the xdata with them.
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 06:37:10 AM
I see...different apps...different methods.

I just found a good property grid example that shows how to add more cool stuff. Now I can lose the code for managing rows and collumns and take advantage of having combos and collapsable rows for arrays and points,etc.

This is as good as it gets. I got it plugged in and working. I never could have figured this way out...but now I see it and can learn from it

I converted it for you C sharpers. I had to comment out a couple of things to get it running in C# but it does most everything
Title: Re: Palette Problem
Post by: smcclure on August 18, 2006, 10:27:36 AM
Ok, this is an unorthodox way of setting entity prop's but I needed it to get and set some xdata but this simple app shows what I was trying to do.

I would like to throw in a suggestion to think about using ICustomTypeDescriptor and PropertyDescriptor to dynamically add/remove properties from the class. I have an example, but it is not ACAD specific if people are interested. Basically, though, you just need to override getProperties in ICustomTypeDescriptor and return whatever PropertyDescriptors you want. It beats making custom classes just to interface with the PropertyGrid.

That said, I dont like PropertyGrid very much and I would suggest a DataGridView instead. The PropertyGrid is a kind of a kluged afterthought, and things like ErrorProviders do not work with it. The DataGridView I believe is a much more robust control.
Title: Re: Palette Problem
Post by: smcclure on August 18, 2006, 10:29:42 AM
Also you should use an ExpandableObjectConverter for any custom objects that have internal properties that must be set for PropertyGrids. It makes that cool collapsible editor that you see for arrays and such.

 - Scott
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 10:51:43 AM
That said, I dont like PropertyGrid very much and I would suggest a DataGridView instead. The PropertyGrid is a kind of a kluged afterthought, and things like ErrorProviders do not work with it. The DataGridView I believe is a much more robust control.

I saw benefits I could not easily do with a datagridview that I could do more easily with the property grid. So I basically did a 180 yesterday.

But I am not going to able to just throw the datagridview away either. I have lots of dynamic list(of t) made up of classes that I need to have in grids as well

I am interested in seeing your example as I am trying to connect up my existing classes to the grid.



EDIT: Fixed those quote tags for ya
Title: Re: Palette Problem
Post by: smcclure on August 18, 2006, 04:07:39 PM
But I am not going to able to just throw the datagridview away either. I have lots of dynamic list(of t) made up of classes that I need to have in grids as well

These can be used inside a PropertyGrid using the method I described above. I tried to pull my example out but I found that there were a ton of dependencies - it is part of the preferences system that my appliication uses, so it has a lot of dependencies. I found a link that describes the method I used more concisely than my code does (it doesnt have the extra junk...) It is available at The Code Project: http://www.codeproject.com/cs/miscctrl/bending_property.asp (http://www.codeproject.com/cs/miscctrl/bending_property.asp)
Title: Re: Palette Problem
Post by: DBARANAS on August 18, 2006, 09:57:32 PM
These can be used inside a PropertyGrid using the method I described above. I tried to pull my example out but I found that there were a ton of dependencies - it is part of the preferences system that my appliication uses, so it has a lot of dependencies. I found a link that describes the method I used more concisely than my code does (it doesnt have the extra junk...) It is available at The Code Project: http://www.codeproject.com/cs/miscctrl/bending_property.asp (http://www.codeproject.com/cs/miscctrl/bending_property.asp)
[/quote]

Thanks!

I think I saw that one during my DataGridView quest. Noiw it makes sense to me and I am working on getting it over to VB to play with it.
Title: Re: Palette Problem
Post by: Glenn R on August 19, 2006, 09:18:53 AM
Quote
Everything I make in the models gets serialized into binary files. All the objectID's are in those files

I really don't see how that's possible, as an ObjectID is a calculated property off the handle. Meaning, a handle is guaranteed to be unique for a file (and autocad files these out in save ops) but is not guaranteed to be unique across multiple drawings. An ObjectID on the otherhand, is guarnateed to be unique across a session as it's calculated off the handle..................................................
Title: Re: Palette Problem
Post by: DBARANAS on August 20, 2006, 12:25:48 PM
Quote
Everything I make in the models gets serialized into binary files. All the objectID's are in those files

I really don't see how that's possible, as an ObjectID is a calculated property off the handle. Meaning, a handle is guaranteed to be unique for a file (and autocad files these out in save ops) but is not guaranteed to be unique across multiple drawings. An ObjectID on the otherhand, is guarnateed to be unique across a session as it's calculated off the handle..................................................

Glenn please explain some more you have me confused.

I can say that everything that I do lives in a single .dwg file
I don't do anything with xrefs or blocks outside of the file I am working in
I keep the project in its own directory with all of the *.dat binary files I create.
I can open up any model and bring things back from the dead and work on them (object ID's or handles (..old VBA))

You have me wondering now. I have been too busy writing lines to test out different scenarios.
If I can store object ID's in a binary file and load them up when I open a project then that is all I need if the objectId's are still the same and I can manipulate solids,etc in a new sesion.

I have had a few problems where the objectID's (or handles) could not drill the AcDB and return objects back to me. I have been ignoring this trying to get the rest of the code up and running.

Since I went .net I haven't seen this in a while and forgot about it
Title: Re: Palette Problem
Post by: Kerry on August 20, 2006, 05:04:02 PM
Dave,
The Handle is stored in the drawing file and is never reused in the same drawing.
An Object ID is assigned when the drawing is opened and may/will be different for each session.
Title: Re: Palette Problem
Post by: Glenn R on August 20, 2006, 07:00:32 PM
What Kerry said.

When a drawing is filed in (DwgFiler from memory) it comes across a handle stored in the dwg and reads it in, then it CALCULATES the objectID based of the handle, the document id and possibly even a session id. The upshot of this is, is that an objectid is a RUNTIME thing and should never be counted on to be the same from drawing to drawing/session to session.

If you need that functionality, store the handle and tie it to a particular drawing.
Title: Re: Palette Problem
Post by: smcclure on August 21, 2006, 10:41:58 AM
Everything I make in the models gets serialized into binary files. All the objectID's are in those files.

If you are using the included .NET serialization functionality, I would watch out. It doesnt appear that the AutoCAD objects are marked as serializable. I would suggest writing each object out manually (using the handle as described below) or, if you are feeling adventurous, make a wrapper object that is serialized has some serializable fields that will write out the handle and retrieve the object from the handle for you.
Title: Re: Palette Problem
Post by: DBARANAS on August 23, 2006, 12:46:53 AM
What Kerry said.

if you need that functionality, store the handle and tie it to a particular drawing.

I hope I got it right. This is what I am doing

make something....

            Dim solid As Solid3d = New Solid3d()
            solid.Extrude(region, height, 0)

            'add it to the db
            btr.AppendEntity(solid)
            trans.AddNewlyCreatedDBObject(solid, True)
            handle = solid.ObjectId.Handle.Value.ToString()  'is this a handle or an objectID?

get it back later......

                    Dim id As ObjectId = db.GetObjectId(False, New Handle(Convert.ToInt64(.silPltHnd)), 0)' same thing here again
                    Dim doclock As DocumentLock = AcAp.DocumentManager.MdiActiveDocument.LockDocument()
                    Dim ent As Entity = DirectCast(trans.GetObject(id, DatabaseServices.OpenMode.ForWrite), Entity)
                    Dim solid As Solid3d = DirectCast(ent, Solid3d)

I am doing this everywhere...I know this thread is going sideways. But now I am not so sure about this
Title: Re: Palette Problem
Post by: MickD on August 23, 2006, 01:33:19 AM
The way you're getting the handle seems ok (I do the same but using an array of id's) so it should be fine.
A way to check is to "LIST" your object with a known handle and see if it indeed exports and imports the same object.
Title: Re: Palette Problem
Post by: Glenn R on August 23, 2006, 01:49:50 AM
Dave, that looks ok.

How are you tying a handle to a particular drawing?
Title: Re: Palette Problem
Post by: DBARANAS on August 23, 2006, 02:58:59 AM
Dave, that looks ok.

How are you tying a handle to a particular drawing?

Right now I have a directory structure set up with binary files, .dwg and the dll so that all I have to do is is build and have it run a .scr and the app fires up. In production I will need a front end. So I have to move directories around which is OK for now.

Everything is in 1 .dwg file and only 1 layer. I do everything(visibility,isolating,editing,deleting,exploding assemblies, moving things,etc) by returning everything back by their handles.

I used to use xdata and lost everything when a dwg file got corrupted. This way I could rebuild a model in a fresh .dwg file if need be. In fact I all care about is having a black modelspace screen to paint pictures. No drafting allowed