Author Topic: Custom propertygrid UITypeEditor inside AutoCAD... Wierd  (Read 11657 times)

0 Members and 1 Guest are viewing this topic.

Chumplybum

  • Newt
  • Posts: 97
Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« on: July 02, 2007, 01:18:08 AM »
hi all,

i have a routine which allows you to edit existing or create new serialised objects (.xml) via a properties grid, some of the properties allow you to browse for a file using a custom UITypeEditor (a linetype file for example, the custom UITypeEditor filters for .lin)... if i run this outside of autocad (ie just using a test application) everything works fine and i can browse for a linetype file until my hearts content... however, if i run this inside autocad using autodesk.autocad.Runtime.CommandMethod("XXXX"), there is no (...) that popup for that property (see attached). I have a few other custom UITypeEditor classes and each of these work fine outside of AutoCAD, but run from within autocad they don't work


has anyone come across this before??? any suggestions???


any help would be great


cheers

Mark

MaksimS

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #1 on: July 02, 2007, 05:35:43 AM »
Mark,

Take a look at the following thread:
http://discussion.autodesk.com/thread.jspa?messageID=5387316

I think they fixed it in AutoCAD 2007.

The other question is - who owns the form displaying property editor?

Regards,
Maksim Sestic
 

hi all,

i have a routine which allows you to edit existing or create new serialised objects (.xml) via a properties grid, some of the properties allow you to browse for a file using a custom UITypeEditor (a linetype file for example, the custom UITypeEditor filters for .lin)... if i run this outside of autocad (ie just using a test application) everything works fine and i can browse for a linetype file until my hearts content... however, if i run this inside autocad using autodesk.autocad.Runtime.CommandMethod("XXXX"), there is no (...) that popup for that property (see attached). I have a few other custom UITypeEditor classes and each of these work fine outside of AutoCAD, but run from within autocad they don't work


has anyone come across this before??? any suggestions???


any help would be great


cheers

Mark

« Last Edit: July 02, 2007, 05:37:42 AM by MaksimS »

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #2 on: July 02, 2007, 06:52:55 PM »
thanks Maksim, i'm currently running AutoCAD 2008 with VS 2005, Windows XP sp2, unfortunately i can't test it on AutoCAD 2007.

when running the form using the following:
ProjectEditorForm.Show()
or
ProjectEditorForm.ShowDialog()
or
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(ProjectEditorForm)

shows the propertiesgrid without the dots (or any custom UITypeEditor), all these a executed from within:
<Autodesk.AutoCAD.Runtime.CommandMethod("ProjectEditor")> _
Public sub ProjectEditorDialog

       'in here......

end sub

so i guess autocad owns them all


however, using this:

System.Diagnostics.Process.Start("C:\Mark\Test\MaxPower.Applications.ProjectEditor.exe")

works the way i think it should work, ie all custom UITypeEditors show up...


thanks again in advance

cheers
Mark

MaksimS

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #3 on: July 03, 2007, 04:22:43 AM »
Mark,

Try with Autodesk.AutoCAD.Windows.Window class as a base class for your ProjectEditorForm, instead of System.Windows.Forms.Form. Still, I don't think this will fix the problem :-) I guess it's just the way you implemented UITypeEditors - they won't fire an exception due to erroneous typecasting (in that case, they just don't work as expected). Try inspecting values passed to TypeEditor _before_ they reach property editor's property bag.

Regards,
Maksim Sestic

thanks Maksim, i'm currently running AutoCAD 2008 with VS 2005, Windows XP sp2, unfortunately i can't test it on AutoCAD 2007.

when running the form using the following:
ProjectEditorForm.Show()
or
ProjectEditorForm.ShowDialog()
or
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(ProjectEditorForm)

shows the propertiesgrid without the dots (or any custom UITypeEditor), all these a executed from within:
<Autodesk.AutoCAD.Runtime.CommandMethod("ProjectEditor")> _
Public sub ProjectEditorDialog

       'in here......

end sub

so i guess autocad owns them all


however, using this:

System.Diagnostics.Process.Start("C:\Mark\Test\MaxPower.Applications.ProjectEditor.exe")

works the way i think it should work, ie all custom UITypeEditors show up...


thanks again in advance

cheers
Mark

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #4 on: July 03, 2007, 06:41:47 PM »
thanks again maksim... i've found the problem :-), but not a solution (or not a preferred solution anyway)

the class with all the custom UItypeEditors is in another project (which also gets netloaded into cad) this seems to be the problem... if i move the class(es) under the same project as my projecteditorform, then it all works as it should. this is not the preferred solution as i then have to copy the same class to each of the projects that i want to use custom UITypeEditors

so i guess the question now is, can i use custom uitypeeditor objects that are in another project??? should i be inheriting something to allow me to implement properly the custom uitypeeditors in the other project???


thanks in advance


cheers

Mark

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #5 on: July 03, 2007, 08:34:48 PM »
Some things off the top of my head:

Is your 'other project' with the editors in it demand loading and if so, when? ie before or after this one?
Have you tried explicitly loading the assembly....net should be doing this, but......

I use these in my batcher and I've never experienced this behaviour, however, they are all in the same .dll.

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #6 on: July 03, 2007, 09:53:58 PM »
glenn, currently i'm explicitly loading in the projects, i've tried loading in the project which contains the ProjectEditorForm before and after the project that contains the Custom UITypeEditors with the same results...

i've got a reference to the project that contains the UITypeEditors in the ProjectEditorForm project so i think it gets loaded in when i netload my ProjectEditorForm as you pointed out


i've just had a thought off the top of my head (haven't tried it yet, but i will)... would it make a difference changing the functions and subs in the Custom UITypeEditor to be shared???


thanks again

cheers

Mark

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #7 on: July 03, 2007, 09:59:33 PM »
Ah...VB...any language without curly braces isn't worth it you know :)

I believe 'vb shared' is equivalent to 'C# static' and in this case I would say no, it wouldn't make any difference.

What's your editor class look like?

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #8 on: July 03, 2007, 11:06:53 PM »
as it is, i'd prefer not to spend hours looking for an upper / lower case letter thats out of place  :-D

and you're right... changing the functions / subs to shared didn't make a difference, in fact it didn't work at all... you can't use shared with overrides and/or mybase which are in the class (see below... class copied from the codeproject)

code (in its entirity):

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Design
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms

#Region " File dialogs"

Public Class OpenFileEditor

    'http://www.codeproject.com/vb/net/UIFilenameEditor.asp

    Inherits System.Drawing.Design.UITypeEditor

    Public Overloads Overrides Function GetEditStyle(ByVal context As _
                    ITypeDescriptorContext) As UITypeEditorEditStyle
        If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
            Return UITypeEditorEditStyle.Modal
        End If
        Return UITypeEditorEditStyle.None
    End Function

    <RefreshProperties(RefreshProperties.All)> _
    Public Overloads Overrides Function EditValue( _
                ByVal context As ITypeDescriptorContext, _
                ByVal provider As System.IServiceProvider, _
                ByVal value As [Object]) As [Object]

        If context Is Nothing OrElse provider Is Nothing _
                OrElse context.Instance Is Nothing Then
            Return MyBase.EditValue(provider, value)
        End If

        Dim fileDlg As FileDialog
        fileDlg = New OpenFileDialog
        fileDlg.Title = "Select " & context.PropertyDescriptor.DisplayName
        fileDlg.FileName = value

        Dim filterAtt As FileDialogFilterAttribute = _
            context.PropertyDescriptor.Attributes(GetType(FileDialogFilterAttribute))
        If Not filterAtt Is Nothing Then fileDlg.Filter = filterAtt.Filter

        If fileDlg.ShowDialog() = DialogResult.OK Then
            value = fileDlg.FileName
        End If

        fileDlg.Dispose()

        Return value

    End Function

End Class

Public Class SaveFileEditor

    'http://www.codeproject.com/vb/net/UIFilenameEditor.asp

    Inherits System.Drawing.Design.UITypeEditor

    Public Overloads Overrides Function GetEditStyle(ByVal context As _
                    ITypeDescriptorContext) As UITypeEditorEditStyle
        If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
            Return UITypeEditorEditStyle.Modal
        End If
        Return UITypeEditorEditStyle.None
    End Function

    <RefreshProperties(RefreshProperties.All)> _
    Public Overloads Overrides Function EditValue( _
                ByVal context As ITypeDescriptorContext, _
                ByVal provider As System.IServiceProvider, _
                ByVal value As [Object]) As [Object]

        If context Is Nothing OrElse provider Is Nothing _
                OrElse context.Instance Is Nothing Then
            Return MyBase.EditValue(provider, value)
        End If

        Dim fileDlg As FileDialog
        fileDlg = New SaveFileDialog
        fileDlg.Title = "Select " & context.PropertyDescriptor.DisplayName
        fileDlg.FileName = value

        Dim filterAtt As FileDialogFilterAttribute = _
            context.PropertyDescriptor.Attributes(GetType(FileDialogFilterAttribute))
        If Not filterAtt Is Nothing Then fileDlg.Filter = filterAtt.Filter

        If fileDlg.ShowDialog() = DialogResult.OK Then
            value = fileDlg.FileName
        End If

        fileDlg.Dispose()

        Return value

    End Function

End Class

<AttributeUsage(AttributeTargets.Property)> _
Public Class FileDialogFilterAttribute

    Inherits Attribute

    Private m_filter As String

    ''' <summary>
    ''' The filter to use in the file dialog in UIFilenameEditor.
    ''' </summary>
    ''' <value></value>
    ''' <remarks>The following is an example of a filter string: "Text files (*.txt)|*.txt|All files (*.*)|*.*"
    ''' </remarks>
    ''' <history>
    '''    [Vadim]    30/12/2003   Created
    ''' </history>
    Public ReadOnly Property Filter() As String
        Get
            Return Me.m_filter
        End Get
    End Property

    ''' <summary>
    ''' Define a filter for the FileNameEditor.
    ''' </summary>
    ''' <param name="filter">The filter to use in the file dialog in FileNameEditor. The following is an example of a filter string: "Text files (*.txt)|*.txt|All files (*.*)|*.*"</param>
    ''' <remarks></remarks>
    ''' <history>
    '''    [Vadim]    30/12/2003   Created
    ''' </history>
    Public Sub New(ByVal filter As String)
        MyBase.New()
        Me.m_filter = filter
    End Sub

End Class

'Public Class FolderBrowserEditor
'    Inherits System.Drawing.Design.UITypeEditor

'    Private _RootFolder As String
'    Protected Overloads Sub InitializeDialog(ByVal fbd As FolderBrowserDialog)
'        With fbd
'            .RootFolder = _RootFolder
'        End With
'    End Sub

'    Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
'        Dim filterAtt As FolderDialogParametersAttribute = _
'               context.PropertyDescriptor.Attributes(GetType(FolderDialogParametersAttribute))

'        _RootFolder = filterAtt.RootFolder

'        Return UITypeEditorEditStyle.Modal
'    End Function
'End Class

'<AttributeUsage(AttributeTargets.Property)> _
' Public Class FolderDialogParametersAttribute : Inherits Attribute
'    Private _RootFolder As String

'    Public ReadOnly Property RootFolder() As String
'        Get
'            Return _RootFolder
'        End Get
'    End Property

'    Public Sub New(Optional ByVal RootFolder As String = "C:\")
'        MyBase.New()
'        _RootFolder = RootFolder
'    End Sub
'End Class

#End Region

#Region " DropDown "

Public Class DropDownBoxEditor

    'http://www.codeproject.com/vb/net/UniversalDropdownEditor.asp

    Inherits UITypeEditor

    Private edSvc As Windows.Forms.Design.IWindowsFormsEditorService
    Private valMemb As ValueMemberAttribute

    Public Overloads Overrides Function GetEditStyle(ByVal context As _
                    ITypeDescriptorContext) As UITypeEditorEditStyle
        If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
            Return UITypeEditorEditStyle.DropDown
        End If
        Return UITypeEditorEditStyle.None
    End Function

    <RefreshProperties(RefreshProperties.All)> _
    Public Overloads Overrides Function EditValue( _
                ByVal context As ITypeDescriptorContext, _
                ByVal provider As System.IServiceProvider, _
                ByVal value As [Object]) As [Object]
        If context Is Nothing OrElse provider Is Nothing _
                OrElse context.Instance Is Nothing Then
            Return MyBase.EditValue(provider, value)
        End If
        Dim att As SourceCollectionAttribute = _
    context.PropertyDescriptor.Attributes( _
                GetType(SourceCollectionAttribute))
        If att Is Nothing Then
            ' nothing we can do here
            Return MyBase.EditValue(provider, value)
        End If
        Me.edSvc = provider.GetService(GetType(Windows.Forms.Design.IWindowsFormsEditorService))
        If Me.edSvc Is Nothing Then
            ' nothing we can do here either
            Return MyBase.EditValue(provider, value)
        End If

        ' prepare the listbox
        Dim lst As New ListBox
        Me.PrepareListBox(lst, att, context)
        If Me.valMemb Is Nothing Then
            lst.SelectedItem = value
        Else
            Me.valMemb.SelectByValue(lst, value)
        End If
        Me.edSvc.DropDownControl(lst)

        ' we're back
        If lst.SelectedItem Is Nothing Then
            value = Nothing
        ElseIf Me.valMemb Is Nothing Then
            value = lst.SelectedItem
        Else
            value = Me.valMemb.GetValue(lst.SelectedItem)
        End If
        Return value
    End Function

    Private Sub PrepareListBox(ByVal lst As ListBox, _
                ByVal att As SourceCollectionAttribute, _
                ByVal context As ITypeDescriptorContext)
        lst.IntegralHeight = True ' resize to avoid partial items
        Dim coll As ICollection = att.Collection(context.Instance)
        If lst.ItemHeight > 0 Then
            If Not coll Is Nothing AndAlso _
                lst.Height / lst.ItemHeight < coll.Count Then
                ' try to keep the listbox small but sufficient
                Dim adjHei As Integer = coll.Count * lst.ItemHeight
                If adjHei > 200 Then adjHei = 200
                lst.Height = adjHei
            End If
        Else ' safeguard, although it shouldn't happen
            lst.Height = 200
        End If
        lst.Sorted = True ' present in alphabetical order
        FillListBoxFromCollection(lst, coll)
        Me.AssignValueMember(lst, context.PropertyDescriptor)
        Me.AssignDisplayMember(lst, context.PropertyDescriptor)
        ' attach event handler
        AddHandler lst.SelectedIndexChanged, AddressOf Me.handleSelection
    End Sub

    Public Shared Sub FillListBoxFromCollection(ByVal lb As ListBox, ByVal coll As ICollection)
        ' prevent flickers and slow downs by entering the mass update mode
        lb.BeginUpdate()
        lb.Items.Clear()
        Dim item As Object
        For Each item In coll
            lb.Items.Add(item)
        Next
        lb.EndUpdate()
        lb.Invalidate()
    End Sub

    Private Sub AssignValueMember(ByVal lc As ListControl, ByVal pd As PropertyDescriptor)
        Me.valMemb = pd.Attributes(GetType(ValueMemberAttribute))
        If Me.valMemb Is Nothing Then Return
        ' maybe one day it'll work by itself...
        lc.ValueMember = Me.valMemb.ValuePropertyName
    End Sub

    Private Sub AssignDisplayMember(ByVal lc As ListControl, ByVal pd As PropertyDescriptor)
        Dim att As DisplayMemberAttribute = pd.Attributes( _
                GetType(DisplayMemberAttribute))
        If att Is Nothing Then Return
        lc.DisplayMember = att.DisplayPropertyName
    End Sub

    Private Sub handleSelection(ByVal sender As Object, ByVal e As EventArgs)
        If Me.edSvc Is Nothing Then Return
        Me.edSvc.CloseDropDown()
    End Sub
End Class

''' <summary>
''' Service attribute to point to the source collection.
''' </summary>
''' <remarks></remarks>
''' <history>
'''    [afiq]    25/12/2003   Created
''' </history>
<Description("Service attribute to point to the source collection."), _
        AttributeUsage(AttributeTargets.All)> _
Public Class SourceCollectionAttribute
    Inherits Attribute
    Private srcCollName As String

    Public ReadOnly Property CollectionName() As String
        Get
            Return Me.srcCollName
        End Get
    End Property

    Public ReadOnly Property Collection(ByVal instance As Object) As ICollection
        Get
            Dim pdc As PropertyDescriptorCollection = _
                    TypeDescriptor.GetProperties(instance)
            Dim pd As PropertyDescriptor
            For Each pd In pdc
                If pd.Name = Me.srcCollName Then
                    Return pd.GetValue(instance)
                End If
            Next
            Return Nothing
        End Get
    End Property

    Public Sub New(ByVal sourceCollectionPropertyName As String)
        Me.srcCollName = sourceCollectionPropertyName
    End Sub
End Class

''' <summary>
''' Specifies the member returning value in the list control used by the dynamic combo editor.
''' </summary>
''' <remarks></remarks>
''' <history>
'''    [afiq]    05/02/2004   Created
''' </history>
<AttributeUsage(AttributeTargets.All)> _
Public Class ValueMemberAttribute
    Inherits Attribute
    Private valMemb As String

    ''' <summary>
    ''' Gets the name of the property used as value member by the dynamic combo type editor.
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ''' <history>
    '''    [afiq]    05/02/2004   Created
    ''' </history>
    <Description("The name of the property used as value member by the dynamic combo type editor.")> _
    Public ReadOnly Property ValuePropertyName() As String
        Get
            Return Me.valMemb
        End Get
    End Property

    Public Sub SelectByValue(ByVal lb As ListBox, ByVal val As Object)
        lb.SelectedItem = Nothing
        Dim item As Object
        For Each item In lb.Items
            If Me.GetValue(item) = val Then
                lb.SelectedItem = item
                Exit Sub
            End If
        Next
    End Sub

    Public Function GetValue(ByVal obj As Object) As Object
        If Me.valMemb = String.Empty Then Return obj
        Dim pi As System.Reflection.PropertyInfo = _
          obj.GetType().GetProperty(Me.valMemb)
        If pi Is Nothing Then Return Nothing
        Return pi.GetValue(obj, Nothing)
    End Function

    ''' <summary>
    ''' Specifies the member returning value in the list control used by the dynamic combo editor.
    ''' </summary>
    ''' <param name="valueMemberPropertyName">The name of the property used as value member by the dynamic combo type editor.</param>
    ''' <remarks></remarks>
    ''' <history>
    '''    [afiq]    05/02/2004   Created
    ''' </history>
    Public Sub New(ByVal valueMemberPropertyName As String)
        Me.valMemb = valueMemberPropertyName
    End Sub

End Class

''' <summary>
''' Specifies the member displayed in the list control used by the dynamic combo editor.
''' </summary>
''' <remarks></remarks>
''' <history>
'''    [afiq]    05/02/2004   Created
''' </history>
<AttributeUsage(AttributeTargets.All)> _
Public Class DisplayMemberAttribute

    Inherits Attribute

    Private dispMemb As String

    ''' <summary>
    ''' Gets the name of the property displayed in the list control used by the dynamic combo editor.
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    ''' <history>
    '''    [afiq]    05/02/2004   Created
    ''' </history>
    <Description("The property displayed in the list control used by the dynamic combo editor.")> _
    Public ReadOnly Property DisplayPropertyName() As String
        Get
            Return Me.dispMemb
        End Get
    End Property

    ''' <summary>
    ''' Specifies the property displayed in the list control used by the dynamic combo editor.
    ''' </summary>
    ''' <param name="displayMemberPropertyName">The name of the property displayed in the dynamic combo type editor.</param>
    ''' <remarks></remarks>
    ''' <history>
    '''    [afiq]    05/02/2004   Created
    ''' </history>
    Public Sub New(ByVal displayMemberPropertyName As String)
        Me.dispMemb = displayMemberPropertyName
    End Sub

End Class

#End Region

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #9 on: July 03, 2007, 11:14:38 PM »
What attributes do you have on the property of the object that is assigned to the particular area of the property grid that you're not getting an ELLIPSIS for?

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #10 on: July 03, 2007, 11:22:57 PM »
glenn, below is one of the properties... i've got a few more that use a dropdown instead of (...) and they're not working either... ie same problem

code below (project name for custom UI's is: MaxPower.Forms, project name for property(below): MaxPower.AutoCAD.r2008):

       Imports MF = MaxPower.Forms

       <System.ComponentModel.Category("General")> _
        <System.ComponentModel.Editor(GetType(MF.OpenFileEditor), GetType(Drawing.Design.UITypeEditor))> _
        <MF.FileDialogFilter("Project Files (*.pxf)|*.pxf")> _
        Public Property Reference() As String
            Get
                Return Me.m_Reference
            End Get
            Set(ByVal value As String)
                If Me.m_Reference IsNot value Then
                    If value.ToLower <> Me.FullPath Then
                        Me.m_Reference = value
                        Me.m_ReferenceObject = TryCast(MaxPower.Utilities.Serialize.XML.Load(value, GetType(ProjectItem)), ProjectItem)
                        Me.Modified = True
                    Else
                        System.Windows.Forms.MessageBox.Show("Circular reference detected" & Constants.vbNewLine & "The reference project cannot be this project", "Circular reference", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Exclamation)
                    End If
                End If
            End Set
        End Property

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #11 on: July 03, 2007, 11:28:21 PM »
OK, your attributes look the same as mine, however your class is quite different in some respects:

Code: [Select]
public class PageSetupFileNameEditor : System.Windows.Forms.Design.FileNameEditor
{

public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) {
return UITypeEditorEditStyle.Modal;
}

public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) {
if (context != null && context.Instance != null && provider != null) {

Autodesk.AutoCAD.Windows.OpenFileDialog fileDlg = null;

OpenFileDlgFlags fileDlgFlags = OpenFileDlgFlags.NoFtpSites | OpenFileDlgFlags.NoUrls | OpenFileDlgFlags.DoNotTransferRemoteFiles;
fileDlg = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select Page Setup File", null, "dwg;dwt", "BatchSettingsDlg", fileDlgFlags);

if (fileDlg.ShowDialog() == DialogResult.OK)
return fileDlg.Filename;
}
// return base.EditValue(context, provider, value);
return value;
}

}

Notice how I'm deriving from FileNameEditor, not UITypeEditor as well as some other cosmetic differences.
I would start with a test project that just does the file picker property and see if you can get that to work.

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #12 on: July 03, 2007, 11:58:29 PM »
ok, converted you're code to vb, and changed names to PageSetupFileNameEditor and still get the same problem... ie no (...)


converted code:
Public Class PageSetupFileNameEditor

    Inherits System.Windows.Forms.Design.FileNameEditor

    Public Overloads Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As UITypeEditorEditStyle
        Return UITypeEditorEditStyle.Modal
    End Function

    Public Overloads Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
        If context IsNot Nothing AndAlso context.Instance IsNot Nothing AndAlso provider IsNot Nothing Then

            Dim fileDlg As Autodesk.AutoCAD.Windows.OpenFileDialog = Nothing

            Dim fileDlgFlags As Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags = Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoFtpSites Or Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoUrls Or Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles
            fileDlg = New Autodesk.AutoCAD.Windows.OpenFileDialog("Select Page Setup File", Nothing, "dwg;dwt", "BatchSettingsDlg", fileDlgFlags)

            If fileDlg.ShowDialog() = DialogResult.OK Then
                Return fileDlg.Filename
            End If
        End If
        '            return base.EditValue(context, provider, value);
        Return value
    End Function

End Class


Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #13 on: July 04, 2007, 12:58:47 AM »
Ok, I found what the problem is: it's assembly resolution...how acad finds the referenced assembly, or in this case, how it doesn't.
Toss your assembly with the editor defs in the acad.exe folder and tell me what you get....

I've run across this before...

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #14 on: July 04, 2007, 01:38:09 AM »
THAT'S IT :-)

so after copying the compiled .dll file with the custom type editors everything works as it should...  now for the big question, is there a fix for this??? or is copying the dll files to the acad directory the way to go???

on a side note, do you find it better to use the autocad select file dialog or the windows one???

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #15 on: July 04, 2007, 01:38:42 AM »
OK,

Toss this somewhere in your startup code for the ProjectEditor:

Code: [Select]
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

You're registering for an event - the AssemblyResolve event in particular, which occurs if resolution fails.

Then implement the event handler:

Code: [Select]
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string partialName = "YourAssemblyNameGoesHere";
if(args.Name.IndexOf(partialName) != -1)
return typeof(YourNamespace.YourEditorClass).Assembly;
else
return null;
}

...and you should be good to go.

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #16 on: July 04, 2007, 01:40:23 AM »
AutoCAD's dialog if I'm dealing with drawings and want the preview image, also I think it's less confusing for the user. They're in acad so give 'em the acad open dialog.

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #17 on: July 04, 2007, 01:43:19 AM »
...or is copying the dll files to the acad directory the way to go???

I never copy anything into acad's standard folder structure nor do I modify any of it's files...does that answer the question?  :-D

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #18 on: July 04, 2007, 02:04:21 AM »
perfect... thanks, i never would have got that :|

and thanks for the tips on the dialogs, i totally agree with you about not touching autocad at all


Cheers and thanks again

Mark

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #19 on: July 04, 2007, 09:27:01 AM »
Say hello to Martin for me  :evil:

Chumplybum

  • Newt
  • Posts: 97
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #20 on: July 04, 2007, 06:17:22 PM »
sure, no worries... small world eh????

Glenn R

  • Guest
Re: Custom propertygrid UITypeEditor inside AutoCAD... Wierd
« Reply #21 on: July 04, 2007, 06:53:30 PM »