Friday, January 21, 2005

Unattended uninstallation using vbscript

"How can I uninstall applications automatically without having to use Windows Add/Remove Programs?"

Here is a tips for how to do. This works for uninstalling most applications. In this example I will show how AutoCAD 2005 can be uninstalled using a VBScript. Open Regedit and look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall search for the application and find a the product code that is in GUID format looking like this: {5783F2D7-0301-0409-0002-0060B0CE6BBA} It might be something else for you. The code below will uninstall AutoCAD 2005 as well as Express Tools. Copy the code below into Notepad and give the file the extension vbs.

on error resume next
Set WshShell = CreateObject("WScript.Shell")
' Uninstall Express Tools
WshShell.Run "msiexec /x {5783F2D7-0311-0409-0000-0060B0CE6BBA} /q",1,true
' Uninstall AutoCAD 2005
WshShell.Run "msiexec /x {5783F2D7-0301-0409-0002-0060B0CE6BBA} /q",1,true

Thursday, January 20, 2005

Sheet Set Manager API code sample for AutoCAD 2005

Some of you have requested a code sample how to use the Sheet Set Manager API for AutoCAD 2005. Here is one that you can download and take a look at.
' Sheet Set Manager sample
' By Jimmy Bergmark
' Copyright (C) 2005 by JTB World
' www.jtbworld.com
' 2005-01-04
'
' SyncLayoutFileName works on the current opened sheet set
' It makes sure that the file name matches the Sheet number
' It makes sure that the layout name is the Sheet number
' concatenated with the Sheet title
' It includes code that shows who is locking the Sheet Set if it's locked
'
' Permission to use, copy, modify, and distribute this software
' for any purpose and without fee is hereby granted, provided
' that the above copyright notice appears in all copies and
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting
' documentation.
'
' JTB World PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
' JTB World SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  JTB World
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.


Public Sub SyncLayoutFileName()
Dim i As Integer
    ' Return how many Sheets Sets that are open
    i = SheetSetsOpen
    If i > 1 Then
        MsgBox "More than one Sheet Set are open. Make sure only one is open.", _
            vbCritical
        Exit Sub
    ElseIf i = 0 Then
        MsgBox "No Sheet Set is open. Make sure one is open.", vbCritical
        Exit Sub
    End If
    
    Dim ssm As New AcSmSheetSetMgr
    Dim dbIter As IAcSmEnumDatabase
    Dim db As IAcSmDatabase
    Dim ss As AcSmSheetSet
    
    If ssm Is Nothing Then
        MsgBox "Something wrong here: 1", vbCritical
        Exit Sub
    End If
    Set dbIter = ssm.GetDatabaseEnumerator
    If dbIter Is Nothing Then
        MsgBox "Something wrong here: 2", vbCritical
        Exit Sub
    End If
    dbIter.Reset
    
    'get the Database of the first sheetset
    Set db = dbIter.Next
    If db Is Nothing Then
        MsgBox "No Sheet Set open", vbCritical
        Exit Sub
    End If
    Set ss = db.GetSheetSet
    If ss Is Nothing Then
        MsgBox "Cannot get the Sheet Set", vbCritical
        Exit Sub
    End If
    Set oSheetIter = ss.GetSheetEnumerator
    If oSheetIter Is Nothing Then
      Exit Sub
    End If
    Dim lockStatus As AcSmLockStatus
    Let lockStatus = db.GetLockStatus
    If lockStatus = AcSmLockStatus_UnLocked Then
      db.LockDb db
    Else
        Call db.UnlockDb(db, True)
        Let lockStatus = db.GetLockStatus
        If lockStatus <> AcSmLockStatus_UnLocked Then
            Dim sUserName As String
            Dim sMachineName As String
            db.GetLockOwnerInfo sUserName, sMachineName
            MsgBox "The Sheet Set is locked by " & sUserName & _
                " at " & sMachineName, vbCritical
            Exit Sub
        End If
    End If
    
    Dim compEnum As IAcSmEnumComponent
    Set compEnum = ss.GetSheetEnumerator
    
    Call LoopThroughSheets(compEnum)
    
    Call db.UnlockDb(db, True)
End Sub

Private Sub LoopThroughSheets(ByVal compEnum As IAcSmEnumComponent)
    Dim bChanged As Boolean
    Dim comp As IAcSmComponent
    Set comp = compEnum.Next()
    Do While Not comp Is Nothing
        If comp.GetTypeName = "AcSmSheet" Then
            Dim s As AcSmSheet
            Set s = comp
            Dim sNumber As String
            Dim sTitle As String
            Debug.Print s.GetNumber
            Debug.Print s.GetTitle
            Debug.Print s.GetDesc
            Dim oLayout As IAcSmNamedAcDbObjectReference
            Set oLayout = s.GetLayout
            Dim sRFN As String

            bFileFound = True
            On Error Resume Next
            sRFN = oLayout.ResolveFileName
            If Err.Number = -2147024894 Then
                MsgBox "The file for Sheet " & oLayout.GetFileName & _
                    " cannot be found." & vbNewLine & "Number: " & _
                    s.GetNumber & " Title: " & s.GetTitle
                bFileFound = False
            End If
            On Error GoTo 0
            If bFileFound Then
            ThisDrawing.Application.Documents.Open (sRFN)
            ThisDrawing.ActiveSpace = acPaperSpace
            ThisDrawing.MSpace = False
            ZoomExtents
            bChanged = False
            If UCase(ThisDrawing.FullName) = UCase(sRFN) Then
                sTitle = s.GetTitle
                sNumber = s.GetNumber
                ' Can fail if there are multiple layouts
                If ThisDrawing.Layouts.Count > 2 Then
                    MsgBox "This drawing has more than one layout " & _
                    "and there might result in some error", vbCritical
                End If
                If ThisDrawing.ActiveLayout.Name <> sNumber & " " & sTitle Then
                    If sNumber = "" Then
                        ThisDrawing.ActiveLayout.Name = sTitle
                    Else
                        ThisDrawing.ActiveLayout.Name = sNumber & " " & sTitle
                    End If
                    bChanged = True
                End If
                ' Compare the referenced layout and file name
                ' The file name should be the same as the Sheet Number
                Dim sSheetFileName As String
                If s.GetNumber = "" Then
                    sSheetFileName = s.GetTitle & ".dwg"
                    MsgBox "The Sheet " & s.GetTitle & _
                    " doesn't have any Sheet Number so the Title is used as file name"
                Else
                    sSheetFileName = s.GetNumber & ".dwg"
                End If
                If oLayout.GetName <> s.GetTitle Or _
                  UCase(sSheetFileName) <> UCase(ThisDrawing.Name) Then
                    oLayout.InitNew s
                    oLayout.SetName ThisDrawing.ActiveLayout.Name
                    If UCase(sSheetFileName) <> UCase(ThisDrawing.Name) Then
                        Dim oldFullName As String
                        Dim newFullName As String
                        newFullName = ThisDrawing.Path & "\" & sSheetFileName
                        If FileExists(newFullName) Then
                            MsgBox newFullName & " already exist"
                        End If
                        oldFullName = ThisDrawing.FullName
                        ThisDrawing.SaveAs newFullName
                        oLayout.SetFileName newFullName
                        On Error Resume Next
                        Kill (oldFullName)
                        On Error GoTo 0
                    Else
                        oLayout.SetFileName ThisDrawing.FullName
                    End If
                End If
            End If
            ThisDrawing.Close bChanged
            End If
        ElseIf comp.GetTypeName = "AcSmSubset" Then
            Dim sset As AcSmSubset
            Set sset = comp
            Call LoopThroughSheets(sset.GetSheetEnumerator)
        End If
        Set comp = compEnum.Next()
    Loop
End Sub

Private Function FileExists(filename As String) As Boolean
    On Error GoTo ErrorHandler
    FileExists = (GetAttr(filename) And vbDirectory) = 0
ErrorHandler:
End Function

Tuesday, January 18, 2005

Picasa 2 for free from Google

Here's a great picture software that Google have released for free. Download it here. I used Hello to publish it on Blogger. This image is quite interesting since it's painted on the ground so it's looking like it's in 3D. Posted by Hello

Tuesday, January 11, 2005

AutoCAD Sheet Set Manager properties shows '----' when you don't want to

Some users of SSM in AutoCAD don't want "----" or "--" (four or two hyphens/dashes) to show up on the plotted drawing when a property is empty.

Using a regular space character as a workaround to not getting "----" doesn't work for AutoCAD 2008 and older. It doesn't stay if the drawing is saved, closed and then opened.

In AutoCAD 2009 and newer if a space is added nothing will show at all, not even the gray area so that you could see that it is a field there. Nothing. That makes it tricky if the field is in a mtext object and nothing else as you will not see it and might delete it unintentionally. Also next time you go in and edit properties the regular space will be removed.

Here is a better tip for empty fields or blank fields.

What on the other hand stays is entering ALT-0160 (Non-break Space) on the keyboard followed by an enter. To do it hold down the ALT key and type the numbers 0 1 6 0 on the numeric keypad. Now the four dashes will not show up their ugly face. You can also enter \U+00A0 as another way but it did not work in all cases. If you don’t have a numeric keypad on your keyboard you can run Character Map (C:\Windows\System32\charmap.exe) and locate the No-Break Space or search for it. Then copy and paste it.

image

An alternative that also can work is to enter %% or %%U in the property value. It does not always work. If a field is added into mtext or multiline block attribute, or in a Sheet Set Table it fails but if a field in a regular block attribute it works.

Note that this may not work for all type of text font styles. If it does not work and for example shows a ? change the style to another like Arial.

Why upgrade to Acrobat Reader 7

Having used the new version 7 for a while I've noticed some things I like about it and that makes it worthwhile to upgrade to. Press CTRL and use the wheel on the mouse lets you zoom in and out easily. This is great when inspecting drawings. The performance has also been improved. More about Acrobat Reader 7 here.

Sunday, January 9, 2005

w.bloggar version 4 released

This post is done with the newly installed v4 if w.bloggar, a great Freeware for posting to you blog. This new version supports MovableType advanced post options and also support some new tools: Wordpress, SquareSpace, b2evolution, Blog:CMS, UBlog, .Text, BlogWare and Xaraya. Check What's New! Here's a screen shot.

Saturday, January 8, 2005

Speed of light and Google calculator

Want to know the speed of light? c is the constant for it. Using Google and enter c will give you the answer. More on the calculator. Try for example to enter an expression like this: 50 miles in km

Live message alerts

Here's another way to subscribe and be notified on new items in a Blog or a RSS feed. With LiveMessage alerts you can get alerts using MSN Messanger.

New live blogroll added

I've now added a live blogroll to my Bloglines and have added code like this to my blog. It grabs the folder CAD from the Bloglines blogroll. <script language="javascript" type="text/javascript" src="http://rpc.bloglines.com/blogroll?id=JTBWorld&folder=CAD&target=_blank"></script>

To show the complete blogroll I use: <script language="javascript" type="text/javascript" src="http://rpc.bloglines.com/blogroll?id=JTBWorld&target=_blank"></script>

Friday, January 7, 2005

Montage-a-google just for fun

Just for fun you can try to make a photo montage of a google image search result. Try to enter AutoCAD for example.

Thursday, January 6, 2005

Microsoft® Windows AntiSpyware (Beta)

I just downloaded, installed and tried Microsoft® Windows AntiSpyware (Beta). No Spyware found this time though.

SnippetCompiler for .NET developers

SnippetCompiler is a great tool for .NET developers. No need to start VS.NET and create a temporary project just because you want to try a small snippet solution. Features:
  • Compiles and runs single or multiple C#, VB.NET and ASP.NET snippets.
  • Optionally builds WinForm EXEs, console EXEs or DLLs.
  • The user can store a library of templates.
  • Displays compile errors and warning, including wave lines in editor with error/warning tooltips.
  • IntelliSense for static members and method signatures, as well as constructor signatures.
  • Imports VS.NET projects.
  • Conveniently sits in the notification area waiting to be useful.
  • Exports snippets to HTML/RTF.

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.