Showing posts with label VB.NET. Show all posts
Showing posts with label VB.NET. Show all posts

Monday, June 02, 2008

ed.SetImpliedSelection(Nothing) doesn't work in AutoCAD 2009

"I upgraded a project to VS 2008 (VB.NET) and AutoCAD 2009 and got this error on the following row:
ed.SetImpliedSelection(Nothing)

Error 1 Overload resolution failed because no accessible 'SetImpliedSelection' is most specific for these arguments:
'Public Sub SetImpliedSelection(selectedObjects() As Autodesk.AutoCAD.DatabaseServices.ObjectId)': Not most specific.
'Public Sub SetImpliedSelection(selectionSet As Autodesk.AutoCAD.EditorInput.SelectionSet)': Not most specific.

Another thing is that SetImpliedSelection is missing in the AutoCAD 2009 .Net API documentation. Not sure if it is on purpose. It was there and worked in AutoCAD 2008.

The object browser still shows it.
Public Sub SetImpliedSelection(ByVal selectedObjects() As Autodesk.AutoCAD.DatabaseServices.ObjectId)
Member of Autodesk.AutoCAD.EditorInput.Editor

The code to replicate this:

Imports Autodesk.AutoCAD Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Namespace SelectionTest Public Class PickfirstTestCmds <CommandMethod("PFT", (CommandFlags.UsePickSet Or CommandFlags.Redraw Or CommandFlags.Modal))> Public Shared Sub PickFirstTest() Dim doc As Document = Application.DocumentManager.MdiActiveDocument() Dim ed As Editor = doc.Editor ed.SetImpliedSelection(Nothing) End Sub End Class End Namespace

I also find that this still works

Dim objs(0) As AcObjectId ed.SetImpliedSelection(objs)

I'm wondering if it is so that ed.SetImpliedSelection(Nothing) is no longer or not really needed to clear the pickfirst set.

Friday, February 29, 2008

Autodesk introduces VSTA

No VSTA (Visual Studio Tools for Applications) in AutoCAD 2009. I read in the CAD Application Development blog that Revit 2009 has it. That means probably AutoCAD 2010 will introduce VSTA unless Autodesk put resources on other things. AutoCAD have at least VBA and AutoLISP something Revit does not have.

Friday, January 18, 2008

Automate testing of GUI

I just subscribed to http://acadguitest.blogspot.com/. I'm looking forward to read more about his finds on "how to test your AutoCAD applications (AutoLISP, VBA, .NET or ObjectARX) against AutoCAD interface."

Fernando Malard have started looking at AutoIt that is a great product for automation.

Via CADptbr

Monday, January 14, 2008

Lambda expressions and mapcar with VB.NET in VS 2008

I've started to work with Visual Studio 2008 and it's great to see that lambda expressions are supported, something I'm familiar with using in AutoLISP.

I also made a simple .NET variant of the mapcar function. If you have another way or better way let me know.

Module Module1 Sub Main() Dim f1 = Function(i, j) If(i >= j, i & " is " & j & " or more", i & " is less than " & j) Console.WriteLine(f1(1, 0)) Console.WriteLine(f1(-1, 1)) Dim s1 = Function(x, y) x + " " + y Console.WriteLine(s1("Jimmy", "Bergmark")) Dim res() As Object = mapcar(Function(x) x * 2, New Integer() {35, 55, 21, 30}) For Each r In res Console.WriteLine(r) Next Dim mult As Func(Of Integer, Func(Of Integer, Integer)) = Function(x As Integer) Function(y As Integer) x * y Dim mult_2 = mult(2) Dim r1 = mult_2(4) ' r1 is now 8 Console.ReadLine() End Sub Function mapcar(ByVal f As Func(Of Object, Object), ByVal ParamArray x() As Object) As Array Dim res(UBound(x(0))) As Object For i As Integer = 0 To UBound(x(0)) res(i) = f(x(0)(i)) Next i Return res End Function End Module

Here is the output of the code.

output

Thursday, December 20, 2007

Using the registry or an INI file to save and retrieve information

When programming there are often information that you want to save and later read. If you consider to use an INI file I suggest you read this post Why are INI files deprecated in favor of the registry?

Here are some reasons I find useful:

  • INI files don't support Unicode.
  • Multiple writers to an INI file can result in data loss.
  • INI files can suffer a denial of service.
  • Parsing an INI file is comparatively slow.

If you think XML is a better choice there are some arguments there as well.

Thursday, November 29, 2007

Extract ISO for Visual Studio 2008 ISO-13346 "UDF"

I downloaded Visual Studio 2008 professional RTM and tried to extract the file en_visual_studio_2008_professional_x86_x64wow_dvd_X14-26326.iso using 7-zip but the only file I got was README.TXT with the following content:
This disc contains a "UDF" file system and requires an operating system
that supports the ISO-13346 "UDF" file system specification.

What I then did that solved this was to run Microsoft Virtual PC 2007 and dragged the ISO file to the CD/DVD icon and then I could drag and drop all files from the virtual PC to the host computer.

Update. A friend send an email and recommended a couple of alternatives. I only tried the first one below.

Virtual CloneDrive is a freeware that virtually mounts the ISO to a drive and it worked great in Vista with the VS 2008 ISO. No 64-bit version yet though.

DAEMON Tools Lite is a freeware that supports both X86 and X64. Be aware that you might want to don't want to or want to uninstall DAEMON Tools Searchbar and Save Now that is included.

Monday, November 05, 2007

Enable Target and Change Icon of shortcuts

Have you tried to right click on a shortcut and found that Target text box is locked, disabled and grayed out? You have also seen that Open File Location is disabled.

Have you wanted to change icon of a shortcut just to find that the Change Icon button for the shortcut is disabled?

Have you tired to Run as administrator and you cannot find it on the right click menu and on Advanced Properties the checkbox cannot be checked?

When I drag a file and drop it on the shortcut it does not launch the program, why is that?

Often I have found this is the case and been irritated about. A typical user case is that you have an AutoCAD shortcut or some other shortcut that you want to take a copy of and add some command line arguments or switch like /p for starting with a specific profile. Depending on the installer sometimes the desktop shortcut is editable but not the shortcut on the Start menu>All Programs.

The solution is not so much help if you have the product installed so this tip is more useful for the IT manager or the CAD manager.

If you have the product already installed it's probably easiest to locate the EXE executable and make a shortcut manually.

Not long ago I found that this is called "advertised shortcuts" and for example Visual Studio installers creates that as default. It can also be set in tools like Wix, InstallShield, Tarma, etc.

Solution or workaround.

You can run a msi file disabling this behavior using
msiexec.exe <path to msi-file> DISABLEADVTSHORTCUTS=1
or
setup.exe DISABLEADVTSHORTCUTS=1

Or you can set it permanently in the MSI file using the free Orca.

If you want to do this more automated it's possible to use a post build event in Visual Studio and then update the MSI file. Included with the Windows Installer SDK there is WiRunSql.vbs that can be used for this purpose. The SQL look like this:
INSERT INTO Property(Property, Value) VALUES ('DISABLEADVTSHORTCUTS ', '1')

Open the MSI file with Orca and add a new row to the Property table use the name DISABLEADVTSHORTCUTS and the value 1.

Now when installing the shortcuts will behave like expected.

From the Windows Installer Guide on MSDN: DISABLEADVTSHORTCUTS Property.

How to use post build with MSBuild to create non-advertised shortcuts.

Advertised shortcuts.

But what is "advertised shortcuts" and when can this be useful?

This can be useful when deploying applications via GPO (Group Policy Object).

Advertised shortcuts ensures that the shortcuts always have an icon, even if users move from machine to machine. The advertised shortcuts also trigger the installation of an application missing on the machine where the user is currently active. More about advertisement.

Thursday, November 01, 2007

SourceAnywhere Hosted update

Among the news are "Added IP Filter functionality." and "Database encryption improved".

 

There is also an interesting white paper describing how the security works with this SaaS (Software as a Service) solution.

For all news in SourceAnywhere Hosted see the news section on Dynamsoft's website.

One thing I noticed after upgrading and when starting the application was a Global Message telling about that a new version is available. It would be better if it knew what version I have installed.

Other than that SourceAnywhere Hosted is really useful when you collaborate with an extended development team. I recommend you to give it a try.

Wednesday, October 31, 2007

Software Licensing and Protection Services from Microsoft

You probably know how easy it is to disassemble .NET code and it took quite a while for Microsoft to come with a solution. This has been a reason why some companies have not made their applications using .NET code. Obfuscating the code has not been good enough. Actually it was another company that came with a solution. Back in January 2007 Microsoft acquired Secured Dimensions and now they are starting to introduce it as a Microsoft service. Take a look at the new website www.microsoft.com/SLPS. SLP Services is about IP protection, license handling.

SLP Code Protector-  Microsoft SLP Code Protector helps protect .NET code against disassembling and decompilation. Helps to protect .NET code from being hacked and reverse engineered.

I evaluated Code Protector a few months ago and it was easy and quick to get it working. It just took an hour or two to get familiar with the procedures and to be able to protect the first application. In the version I tried, it was not easy to protect DLL code that for example is to be used in-process like a DLL that needs to be loaded with NETLOAD in AutoCAD. There were workarounds for it I didn't care to try and it might be solved by now.

SLP Server 2008 - SLP Server 2008 enables software vendors and publishers to more flexibly and effectively monetize their software. With a new concept Microsoft call “SKU Agility,” the ISV can create multiple offers based on a single image of the software simply by creating digital licenses that map to pre-defined features. Features can be sold individually or accumulated into a set to create SKUs.

Licensing and Activation - are tools to help prevent piracy and serves multiple purposes – protection, license delivery, upselling, and customer service.

A while ago I got a survey from PreEmptive that got me thinking they would come up with a new solution. I now see that PreEmptive Solutions is one of the resellers for SLPS. Dotfuscator has also been extended to instrument (inject) SLPS software into .NET applications.

For more information: The SLPS blog is here and SLPS on MSDN.

Wednesday, October 17, 2007

HKEY_CLASSES_ROOT (HKCR) key description

imageHere is a tip. Avoid writing, deleting or merging (like .REG files or using regedit.exe) to HKEY_CLASSES_ROOT.

Why?

Basically because HKCR is a merged view based on HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes and it can be confusing as to if this will work for the current user, a new user, the administrator user or so.

The registry system uses the following rules to merge information from the two sources:

  • The merged view includes all subkeys of the HKEY_CURRENT_USER\Software\Classes key.
  • The merged view includes all immediate subkeys of the HKEY_LOCAL_MACHINE\Software\Classes key that do not duplicate the subkeys of HKEY_CURRENT_USER\Software\Classes.
  • Below is a list of subkeys that are found in both HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes. The immediate subkeys of these keys from the HKEY_LOCAL_MACHINE tree are included in the merged view only if they are not duplicates of immediate subkeys from the HKEY_CURRENT_USER tree. The merged view does not include the HKEY_LOCAL_MACHINE contents of duplicate subkeys.

The following subkeys are found in both HKEY_LOCAL_MACHINE\Software\Classes and HKEY_CURRENT_USER\Software\Classes. From the HKEY_LOCAL_MACHINE tree, the immediate subkeys of these keys are included in the merged view only if they are not duplicates of immediate subkeys from the HKEY_CURRENT_USER tree. The merged view does not include the HKEY_LOCAL_MACHINE contents of duplicate subkeys.

*
*\shellex
*\shellex\ContextMenuHandlers
*\shellex\PropertySheetHandlers
AppID
ClsID
Component Categories
Drive
Drive\shellex
Drive\shellex\ContextMenuHandlers
Drive\shellex\PropertySheetHandlers
FileType
Folder
Folder\shellex
Folder\shellex\ColumnHandler
Folder\shellex\ContextMenuHandlers
Folder\shellex\ExtShellFolderViews
Folder\shellex\PropertySheetHandlers
Installer\Components
Installer\Features
Installer\Products
Interface
Mime
Mime\Database
Mime\Database\Charset
Mime\Database\Codepage
Mime\Database\Content Type
Typelib

The HKCR key contains file extension associations and COM class registration information such as ProgIDs, CLSIDs, and IIDs.

More is found in this MSDN document.

Wednesday, October 03, 2007

Review of Dynamsoft software version control

imageI've started to try Dynamsoft SourceAnywhere Hosted and will post more as I continue using it.

I use it together with Visual Studio 2005 but also with other file formats like AutoLISP (Visual LISP) files. There is no limitation on what type of files that can be hosted.

It was very straight forward and intuitive to start using SourceAnywhere Hosted. So far so good.

dynamsoft

If you too want to try it they have a Free Hosting Plan for up to to 3 users and 15M storage space.

image

Disclaimer. I was offered for free a plan of Dynamsoft SourceAnywhere Hosted that receives the same service as the paid account.

Thursday, September 27, 2007

ObjectDBX/RealDWG using VB.NET

acdbmgd.dll contains ObjectDBX/RealDWG managed types (everything to do with manipulating drawing files).

ObjectDBX is useful because you directly access the DWG file without adding the extra resources needed to actually show the drawing. This means that the performance is really good. All entities, objects based on AcadObject and dictionaries can be accessed.

You cannot have a freestanding application that uses ObjectDBX unless you have AutoCAD running. Either a DLL must be created that is loaded from within AutoCAD with the NETLOAD command or you need to use ActiveX to access or connect to ObjectDBX using the AcadApplication object and the GetInterfaceObject method.

ObjectDBX is actually renamed to RealDWG and if you need to use it without having AutoCAD you need to purchase and license it. RealDWG does not require the presence of AutoCAD software. RealDWG 2008 is the latest version available now.

Below is a sample that starts AutoCAD 2008 and opens a drawing with ObjectDBX.

Private Function StartAutoCAD() As Object On Error Resume Next Dim AcadApp As Object ' Get the active session of AutoCAD using late binding AcadApp = GetObject(, "AutoCAD.Application.17.1") If Err.Number <> 0 Then Err.Clear() Shell("c:\Program Files\Common Files\Autodesk Shared\WSCommCntr1.exe", AppWinStyle.NormalFocus) ' Create a new session of AutoCAD using late binding AcadApp = CreateObject("AutoCAD.Application.17.1") End If Return AcadApp End Function Private Sub Test() Dim AcadApp As Object Dim dbxDoc As Object AcadApp = StartAutoCAD() If AcadApp Then AcadApp.Visible = True objDbx = AcadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.17") objDbx.Open("D:\test\block1.dwg") Dim ms As Object ms = objDbx.ModelSpace MsgBox(ms.Count.ToString + " objects in in model space") objDbx = Nothing AcadApp.Application.Quit() AcadApp = Nothing End If End Sub

See also ObjectDBX sample using VBA and AutoCAD 2008 and Copy dimstyles between drawings using VBA for other posts how to use ObjectDBX.

Tuesday, September 25, 2007

Custom DateTime Format Specifiers problem solved

Just wanted to share this problem that can show up if you are developing using for for example VB.NET or C# and want to force a custom date and time format.

The problem can show up with format specifiers %t that represents the first character of the A.M./P.M. designator or tt that represents the A.M./P.M. designator.

Notice how PM is missing if the culture is Swedish.

System.Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("sv-SE")
Dim MyDate As New DateTime(2007, 9, 12, 17, 30, 0)
Dim MyString As String = MyDate.ToString("MMM dd 'at' h:mm tt")
MyString returns "sep 12 at 5:30 "

The solution is to set the culture to one that supports AM and PM like en-US and then you can restore it to what it was before.

System.Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Dim MyDate As New DateTime(2007, 9, 12, 17, 30, 0)
Dim MyString As String = MyDate.ToString("MMM dd 'at' h:mm tt")
MyString returns "Sep 12 at 5:30 PM"

Wednesday, September 05, 2007

Annotation scaling and annotation scale list in AutoCAD 2008

Annotation scaling is one of the greatest news in AutoCAD 2008, AutoCAD 2008 LT and all verticals. Text, Mtext, Dimensions, Leaders, Multileaders (new), Tolerances, Blocks, Attributes, and Hatches can now be presented in different ways depending on the annotation scale.

Things that been quite difficult and error prone before AutoCAD 2008 are now really easy. Typical usages are details in different scales. Room numbers on plans in different scales but with different text size as well as location when needed.

Notice below how the room text is visualized in different sizes and angles and if you make a change to the room description it changes on both views.

image

Heidi Hewett's Blog has a whole series and a white paper on the subject

Lynn Allen also has an article on Cadalyst. Circles and Lines: Awesome Annotation Scaling.

Here are some hints for the AutoLISP programmer or scripter.

The standard scale list in AutoCAD 2008 is unfortunately hard coded so you cannot change that one. You can set up your templates having only the scales you want though.

The scales can be added and deleted using different methods.

One is using the command line (especially useful if limited to AutoCAD 2008 LT) but that has it's problems depending on if they already exist or not exist:
(command "-scalelistedit"
"add" "1:2" "1:2"
"add" "1:5" "1:5"
"exit")

(command "-scalelistedit"
"delete" "1:2"
"delete" "1:5"
"exit")

This can be useful to reset the scale list to default entries:
(command "-scalelistedit" "reset" "yes" "exit")

The scale list is saved in an object dictionary so you can access it using:
(dictsearch (namedobjdict) "ACAD_SCALELIST")

If you want to delete all manually added scales:
(dictremove (namedobjdict) "ACAD_SCALELIST")

Some samples how this is implemented can be found in the newsgroups.
ScaleListDel.lsp here, Here and here.

Other related posts:

Monday, September 03, 2007

Saving passwords in a database? No!

So how can it be handled in a better way technically speaking? Referencing to the previous post.

Saving passwords in a database as plain text is really a bad idea. Should the passwords be stored in the database encrypted? No, that is not safe either.

Hashing is the way to go. In .NET System.Security.Cryptography you can convert the password into hashes using SHA1 or MD5. Hashing algorithms are one-way, so there is no
way to "unhash" something into a password again if you need to retrieve it. The only thing that can be done is to validate that the password is correct by hashing it and comparing it to the saved hash value. That is why some sites offer you to reset the password but they cannot show you your password.

System.Web.Security namespace has the FormsAuthentication.HashPasswordForStoringInConfigFile Method.

Dim hashedPassword As String
hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, hashMethod)

hashMethod can be either "MD5" or "SHA1"

Example: hashing the password 'test' gives the hash: 'ogF4I9nCJZCyYFP0azRLIS5wbvFdmlaHt5krTFW9RirYCdC3SgLbhngWGxYHOKXQ'

But this is still not enough. What if two or more users has the same password. That means that if you manage to get the password from one user you automatically have the password for other users with the same password. This can be exploited in a so called dictionary attack. Why is that? Most users actually uses simple passwords that exists in a dictionary. What the hacker does is to create hashes of a lot of words or passwords and can then compare these hashes to the hashes saved in the database.

Salting hashes is the next step to take. That means that a random string is generated and combined with the password and then hashed. So each user credential row has both a hash as well as a random salt string saved in the database. This will make all hashes unique.

Example: hashing the password 'test' combined with the salt 'Djf983jDJ#64)-d2' gives the hash: '57cjEal0b2+hNRT4sLc2eHL6m/0omTpKk8bkSF8osu9mNF0HG+H6HMFHYzzcR6RR'

This makes it a lot harder for the hacker since he would have to hash all his maybe 1,000,000 dictionary entries with the salt of every user row. That will take so much more time.

So the tip for those that want makes websites that needs to register users or needs to validate passwords one way or the other, do not ever save a clear text password in your database, hash it and use a bit of salt.

There are also other ways to handle web authentication. Take a look at Windows CardSpace and OpenID. OpenID is something you will see more of on Internet, that is for sure.

Update. You can read these posts including comments for more detailed information. Enough With The Rainbow Tables: What You Need To Know About Secure Password Schemes and 2 posts by Coding Horror, Rainbow Hash Cracking and You're Probably Storing Passwords Incorrectly

Tuesday, August 28, 2007

Lines, ovals, and rectangles on forms in Visual Basic 2005

Some basic controls where missing in Visual Studio for a while but now they are included in the released Microsoft Visual Basic 2005 Power Packs 2.0.

image

The workaround to draw a line before was to use this tip in the post "Draw a line at design time in Visual Studio".