Jump to content

Recommended Posts

Posted

I am just starting to play around with using vb.net with AutoCAD 2009. I have experience using VBA and Lisp so I'm not a total noob, but i'm totally stuck nonetheless.

 

I'm running AutoCAD 2009 on 32bit Vista and am programming using vb.Net express 2008.

 

I downloaded the code for "introduction to .net programming" and am trying to get one of the sample commands to work as I go through the tutorial. http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627

 

Here's the code I have: (copied straight from the sample code)

 

[size=2][color=#008000][size=2][color=#008000]' declare a paletteset object, this will only be created once[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2] myPaletteSet [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Autodesk.AutoCAD.Windows.PaletteSet[/size]
[size=2][color=#008000][size=2][color=#008000]' we need a palette which will be housed by the paletteSet[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2] myPalette [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] UserControl1[/size]
[size=2][color=#008000][size=2][color=#008000]' palette command[/color][/size]
[/color][/size][size=2]<CommandMethod([/size][size=2][color=#a31515][size=2][color=#a31515]"palette"[/color][/size][/color][/size][size=2])> _[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]Public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size][/color][/size][size=2] palette()[/size]
[size=2][color=#008000][size=2][color=#008000]' check to see if it is valid[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size][/color][/size][size=2] (myPaletteSet = [/size][size=2][color=#0000ff][size=2][color=#0000ff]Nothing[/color][/size][/color][/size][size=2]) [/size][size=2][color=#0000ff][size=2][color=#0000ff]Then[/color][/size]
[/color][/size][size=2][color=#008000][size=2][color=#008000]' create a new palette set, with a unique guid[/color][/size]
[/color][/size][size=2]myPaletteSet = [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] PaletteSet([/size][size=2][color=#a31515][size=2][color=#a31515]"My Palette"[/color][/size][/color][/size][size=2], [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] Guid([/size][size=2][color=#a31515][size=2][color=#a31515]"D61D0875-A507-4b73-8B5F-9266BEACD596"[/color][/size][/color][/size][size=2]))[/size]
[size=2][color=#008000][size=2][color=#008000]' now create a palette inside, this has our tree control[/color][/size]
[/color][/size][size=2]myPalette = [/size][size=2][color=#0000ff][size=2][color=#0000ff]New[/color][/size][/color][/size][size=2] UserControl1[/size]
[size=2][color=#008000][size=2][color=#008000]' now add the palette to the paletteset[/color][/size]
[/color][/size][size=2]myPaletteSet.Add([/size][size=2][color=#a31515][size=2][color=#a31515]"Palette1"[/color][/size][/color][/size][size=2], myPalette)[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]If[/color][/size]
[/color][/size][size=2][color=#008000][size=2][color=#008000]' now display the paletteset[/color][/size]
[/color][/size][size=2]myPaletteSet.Visible = [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size]
[/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Sub[/color][/size]
[/color][/size]

 

So the code would work, I created a usercontrol with a treeview on it, and nothing else. It is named usercontrol1.

 

The code is erroring out at the line:

myPaletteSet.Add("Palette1", myPalette)

 

I am getting the following error returned to me:

 

"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

 

and a snippet from the exception detail:

 

"System.Security.SecurityException was unhandled by user code"

 

Any ideas from the more experienced programmers out there?

Posted

After some digging around I found out that the problem is that the .dll I was loading was on a network drive and this was causing some sort of permission issue with .net when loading a palette.

 

Once I moved the .dll onto my local drive everything seemed to work just fine.

 

If any of you have additional insite on this, let me know.

 

Thanks,

 

Joe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...