Generate a list of all profiles and check if a profile already exists

Generate a list of all profiles and check if a profile already exists

juan.c.ayala
Participant Participant
1,254 Views
1 Reply
Message 1 of 2

Generate a list of all profiles and check if a profile already exists

juan.c.ayala
Participant
Participant

I normally do all of my profile management via LISP and VLISP but I am trying to migrate things over to VBA. I am struggling to find a way to generate a list of all of the profiles that exist in the current AutoCAD session. I dont think I am using GetAllProfileNames properly. I would like to use If InStr to check if a specific profile exists. See code below. I get a type mismatch because I am comparing a Variant to a string, how can I compare the 2 or convert one to the other?

Public PROJECT_SPath1 As String
Public PROJECT_SPath2 As String
Public PROJECT_SPath3 As String
Public PROJECT_SPath4 As String
Public PROJECT_SPath5 As String
Public PROJECT_SPath6 As String
Public PROJECT_SPath7 As String
Public PROJECT_SPath8 As String
Public PROJECT_SPath9 As String
Public PROJECT_SPath10 As String
Public PROJECT_SPath11 As String
Public PROJECT_SPath12 As String
Public PROJECT_SPath13 As String
Public PROJECT_TPath As String
Public PROJECT_CTBSTBPath As String
Public PROJECT_DWTPath As String
Public PROJECT_QNEW As String
Public PROJECT_ToolPalettePath
Public ACADVER As String
Public SL_SERVERNAME As String
Public SL_LAN As String
Public SL_LCL As String
Public SL_LCLPRJDIR As String
Public SL_LANPRJDIR As String
Public SL_CURRPFILE As String
Public SL_USERCUIX As String
Public SL_CUIXSRC As String
Public ACAD_SuppPaths As String
Public ACADCurrPfile As String
Public SL_LANTOOLS As String
Public SL_LCLTOOLS As String
Public SL_LANCADDINFO As String
Public SL_LCLCADDINFO As String
Public SL_LANCUIX As String
Public SL_LCLCUIX As String
Public SL_LANSupport As String
Public SL_LCLSupport As String
Public ACAD_TrustedPaths As String
Public SL_ACTIVE_PRJDIR As String

Public Sub PROJECT_ADDPATHS()
Dim RD_File As String
Dim ACAD_SuppPaths As String
Dim ACAD_RasterPath As String
Dim SL_LANIcons As String
Dim SL_LCLIcons As String
Dim ACAD_TrustedPaths As String
Dim SL_LoadedMenus As String
Dim menuGroup As AcadMenuGroup
Dim SL_LANMENU As String
Dim SL_LCLMENU As String
Dim MyTemplate As AcadPreferencesFiles
Dim strMyProfile As String
Dim UserProfiles As Variant
Dim Profiles As String

strMyProfile = "COMED_2018_LAN"
ThisDrawing.Application.Preferences.Profiles.GetAllProfileNames UserProfiles
SL_SERVERNAME = Environ("SERVERNAME")
ACAD_TrustedPaths = ThisDrawing.GetVariable("trustedpaths")
ACAD_SuppPaths = ThisDrawing.Application.Preferences.Files.SupportPath
ACAD_RasterPath = "C:\Program files\Autodesk\AutoCAD Raster Design 2018"

SL_LANPRJDIR = "\\" & SL_SERVERNAME & "\SYS3\Appl\CAData\SNL-main\Pdata\ACAD-Projects"
SL_LCLPRJDIR = "D:\SLCADD\Pdata\ACAD-Projects"

If Dir(SL_LANPRJDIR) <> " " And Not InStr(1, UCase(UserProfiles), UCase(strMyProfile)) > 0 Then
ThisDrawing.Application.Preferences.Profiles.ImportProfile strMyProfile, SL_LANPRJDIR & "\" & "TemplateProfile.arg", True
ThisDrawing.Application.Preferences.Profiles.ActiveProfile = strMyProfile
ThisDrawing.Application.Preferences.Profiles.ResetProfile strMyProfile
ElseIf Dir(SL_LANPRJDIR) <> " " And InStr(1, UCase(UserProfiles), UCase(strMyProfile)) <> 0 Then
ThisDrawing.Application.Preferences.Profiles.ActiveProfile = strMyProfile
MsgBox "The " & strMyProfile & "profile already exists and has been made the current profile." & vbNewLine & "If you are having issues with the " & strMyProfile & "profile, use the Repair" & strMyProfile & " to try and resolve any issues with this profile."
Else
MsgBox "Unable to determine status of the " & strMyProfile & " Please contact CAE Administration for assistance."
End If

 

0 Likes
1,255 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

The variable "UserProfiles" is a Variant type (an array of string values), not a String type, so you cannot use String handling functions, such as UCase(), InStr()... against an array. That is, UserProfiles contains a list of available profile names, and you need to loop through the list to find a particular profile name, something like:

 

Dim i as Integer

Dim pName As String

For i=0 to UBound(UserProfiles)

    pName=UCase(UserProfile(i))

    If pName = UCase(strMyProfile) Then     '' or you can: If InStr(pName, UCase(strMyProfile))>0 Then...

       '' Found target profile

    End If

Next

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes