Maintaining VBscript in property set code to updated API version - Help

Maintaining VBscript in property set code to updated API version - Help

cyberflow
Advisor Advisor
2,101 Views
31 Replies
Message 1 of 32

Maintaining VBscript in property set code to updated API version - Help

cyberflow
Advisor
Advisor

Hi all,

I'm in the process of update my code that worked fine with my C3D 2023 and now adding the code to cover 2025 i've received error messages "PLN is null or empty)" :

cyberflow_0-1739546189313.png

 



I've always found that VBscript always execute oddly - Might be an impression or i'm just really missing something here ...

I've adjusted/added lines 14 to 18 : 

Dim oCivilApp, oDocument, oPipeNetworks, oPipeNetwork, oPipe, oNetworkObjectID, found, InputHandle, sPipeNetworkName, sAcadVer
Dim fs, logFile, sC3DVer

RESULT = "--"
On Error Resume Next

InputHandle = "[Handle]" ' Replace with the actual handle you want to search for
found = False

' Initialize the AutoCAD application object
Set oApp = GetObject(, "AutoCAD.Application")
sAcadVer = oApp.Version

If InStr(sAcadVer, "25.0") > 0 Then
	sC3DVer = "13.7"
ElseIf InStr(sAcadVer, "24.3") > 0  Then
	sC3DVer = "13.6"
ElseIf InStr(sAcadVer, "24.2") > 0  Then
	sC3DVer = "13.5"
ElseIf InStr(sAcadVer, "24.1") > 0  Then
	sC3DVer = "13.4"
ElseIf InStr(sAcadVer, "24.0") > 0  Then
	sC3DVer = "13.3"
ElseIf InStr(sAcadVer, "23.1") > 0  Then
	sC3DVer = "13.2"
ElseIf InStr(sAcadVer, "23.0") > 0  Then
	sC3DVer = "13.1"
End if

Dim interfaceVersion
interfaceVersion = "AeccXUiPipe.AeccPipeApplication." & sC3DVer
Set oCivilApp = oApp.GetInterfaceObject(interfaceversion)

' Access the active document
On Error Resume Next
Set oDocument = oCivilApp.ActiveDocument

' Get the pipe networks collection
Set oPipeNetworks = oDocument.PipeNetworks

' Iterate through pipe networks
For Each oPipeNetwork In oPipeNetworks   
    If Not IsNull(oPipeNetwork.Pipes) And Not IsEmpty(oPipeNetwork.Pipes) Then
        For Each oPipe In oPipeNetwork.Pipes
            If oPipe.Handle = InputHandle Then
                sPipeNetworkName = oPipeNetwork.Name
                found = True
                Exit For
            End If
        Next
    End If
    If found Then
        Exit For
    End If
Next

    If Not IsNull(oPipeNetwork) Then
        Set PLN = oPipeNetwork.ReferencePartList
        ' Check if part list is valid
        If Not IsNull(PLN) And Not IsEmpty(PLN) Then
                ' Determine result based on part list name
                 Select Case PLN.Name
	Case "AIR COMPRIMÉ EXISTANT"
		RESULT = "AIR COMPRIMÉ EXISTANT"
	Case "AIR COMPRIMÉ PROPOSÉ"
		RESULT = "AIR COMPRIMÉ PROPOSÉ"
	Case "AQUEDUC DÉMOLITION", "AQUEDUC DÉSAFFECTER", "AQUEDUC EXISTANT", "AQUEDUC PROPOSE", "AQUEDUC FUTURE"
		RESULT = "A"
	Case "GAZ EXISTANT"
		RESULT = "G"
                    Case "PLUVIAL EXISTANT", "PLUVIAL PROPOSE", "PLUVIAL DÉMOLITION", "PLUVIAL DÉSAFFECTER", "PLUVIAL FUTURE", "PONCEAU EXISTANT", "PONCEAU PROPOSE"
                        RESULT = "P"
                    Case "REFOULEMENT PLUVIAL EXISTANT", "REFOULEMENT PLUVIAL PROPOSE"
                        RESULT = "RFP"
                    Case "REFOULEMENT SANITAIRE EXISTANT", "REFOULEMENT SANITAIRE PROPOSE"
                        RESULT = "RFS"
                    Case "REFOULEMENT UNITAIRE EXISTANT", "REFOULEMENT UNITAIRE PROPOSE"
                        RESULT = "RFU"
                    Case "SANITAIRE EXISTANT", "SANITAIRE PROPOSE", "SANITAIRE DÉMOLITION", "SANITAIRE DÉSAFFECTER", "SANITAIRE FUTURE"
                        RESULT = "S"
                    Case "UNITAIRE EXISTANT", "UNITAIRE PROPOSE", "UNITAIRE DÉMOLITION", "UNITAIRE DÉSAFFECTER", "UNITAIRE FUTURE"
                        RESULT = "U"
					Case "MASSIF ÉLECTRIQUE EXISTANT (BÉTON ARMÉ)", "MASSIF ÉLECTRIQUE EXISTANT (BÉTON)", "MASSIF ÉLECTRIQUE PROPOSE (BÉTON ARMÉ)", "MASSIF ÉLECTRIQUE PROPOSÉ (BÉTON)"
						RESULT = "MASSIF ÉLEC."
					Case "MASSIF FIBRE OPTIQUE EXISTANT (BÉTON ARMÉ)", "MASSIF FIBRE OPTIQUE EXISTANT (BÉTON)", "MASSIF FIBRE OPTIQUE PROPOSE (BÉTON ARMÉ)", "MASSIF FIBRE OPTIQUE PROPOSE (BÉTON)"
						RESULT = "MASSIF FIBRE OPTIQUE"
					Case "MASSIF TÉLÉPHONIE EXISTANT (BÉTON ARMÉ)", "MASSIF TÉLÉPHONIE EXISTANT (BÉTON)", "MASSIF TÉLÉPHONIE PROPOSE (BÉTON ARMÉ)", "MASSIF TÉLÉPHONIE PROPOSE (BÉTON)"
						RESULT = "MASSIF TEL."
                    Case Else
                        RESULT = "--"
                End Select
            'Else
                'RESULT = "PLN.Name is not a string. It is a " & TypeName(PLN.Name)
            'End If
        Else
            RESULT = "PLN is null or empty"
        End If
    Else
        RESULT = "Object not retrieved from handle"
    End If



 
Anyone see's something i'm missing out here ?

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
2,102 Views
31 Replies
Replies (31)
Message 2 of 32

Anton_Huizinga
Advocate
Advocate

Do you have a small example drawing available?

0 Likes
Message 3 of 32

cyberflow
Advisor
Advisor

For some obscur reason, last week my update didnt work but today it works without any issues : 


Update portion : 

If InStr(sAcadVer, "25.0") > 0 Then
	sC3DVer = "13.7"
ElseIf InStr(sAcadVer, "24.3") > 0  Then
	sC3DVer = "13.6"
ElseIf InStr(sAcadVer, "24.2") > 0  Then
	sC3DVer = "13.5"
ElseIf InStr(sAcadVer, "24.1") > 0  Then
	sC3DVer = "13.4"
ElseIf InStr(sAcadVer, "24.0") > 0  Then
	sC3DVer = "13.3"
ElseIf InStr(sAcadVer, "23.1") > 0  Then
	sC3DVer = "13.2"
ElseIf InStr(sAcadVer, "23.0") > 0  Then
	sC3DVer = "13.1"
End if

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
Message 4 of 32

Anton_Huizinga
Advocate
Advocate

Ah, I think I know what happened. You probably had Civil 3D 2023 and 2025 open at the same time. It is very weird but then the VB code in 2025 thinks it is running in 2023.

 

So you need to close one of the Civil 3D versions to avoid this problem.

Message 5 of 32

cyberflow
Advisor
Advisor

Ahhh that makes sens Anton - I was working several things last week.

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
Message 6 of 32

Jeff_M
Consultant
Consultant

@Anton_Huizinga In the attached dwg there is a PSet Style named BaseObjects with 1 PsetDefinition AcadBase. I have it attached to the single line object in the dwg. This works fine in every release I've used it except C3D 2025. There are no other instances of AutoCAD running. Any idea why I cannot get this, or @cyberflow s, code to work in 2025?

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 7 of 32

Anton_Huizinga
Advocate
Advocate

Here it works fine:

 

Anton_Huizinga_0-1739860874229.png

 

You are sure you only have Civil 3D 2025 open? 

0 Likes
Message 8 of 32

Jeff_M
Consultant
Consultant

Yep, only Civil 3D 2025 is open:

2025-02-18_09-30-04.png

I also noticed that I was running with Update 1 installed. So I grabbed Update 2, installed that, still getting the error. I also have the AutoCAD 2025 1.1 update installed. 

I do not actually use PropertySets, however I do help others with creating, maintaining, and writing code to get/put data from/to PropertySets, so using a different release is not a big issue. I just find it rather odd that I can work with with them in Civil 3D 2021 through 2024 without a problem but 2025 throws a fit. I guess my next step would be a full uninstall/reinstall...

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 9 of 32

Anton_Huizinga
Advocate
Advocate

Actually, it does not give an error, but the function is returned as string instead of an evaluated function. I've seen this before, and someone thought it happened when Windows 11 was installed on a computer that already had Civil 3D 2025. After a full reinstall of 2025, the function was processed instead of returned as string.

0 Likes
Message 10 of 32

Anton_Huizinga
Advocate
Advocate

Thanks! You can set my answer as solution 😉

0 Likes
Message 11 of 32

Jeff_M
Consultant
Consultant

Yes, I've seen that Win11 note as well. However, this laptop came with Win 11 on it so all Civil 3D release I have here were installed into Win 11. However, I know that there were some issues with other things after installing one of the major Win 11 updates. One of those was that the ability to add/edit pipes was lost due to a msscript.ocx error. I just started seeing that today in 2025 😫 so I guess that reinstall will be happening in the next day or two.

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 32

hippe013
Advisor
Advisor

Subscribing to this thread. 👀

Message 13 of 32

Jeff_M
Consultant
Consultant

UPDATE:  After uninstalling Civil 3D 2025, restarting the PC, Installing Civil 3D 2025, restarting, installing Update 2 (I skipped the update 1, the readme for update 2 did not state whether update 1 must be installed first), fired up Civil 3D 2025 and all is well again. The PSet code works, I can create & edit pipes, and it loads fast again. It had been sticking on loading the AeccUiModel.arx file for 2-3 minutes for the past month.

Jeff_M, also a frequent Swamper
EESignature
Message 14 of 32

cyberflow
Advisor
Advisor

My topic was more on a way to to automaticly get the Acad version and C3D version automaticly without needing to update the VBscript code each time a new version is out of C3D 😛

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
Message 15 of 32

Anton_Huizinga
Advocate
Advocate

Ah, I misunderstood that 🙂

0 Likes
Message 16 of 32

Jeff_M
Consultant
Consultant

@cyberflow Sorry for hijacking your thread. As for your initial question "is there a way to to automaticly get the Acad version and C3D version automaticly without needing to update the VBscript code each time a new version is out of C3D"...

I have tried to use what I have been using in my .NET apps to achieve this without success. 

 

However, I have found a method that does work! Stay tuned...

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 17 of 32

Jeff_M
Consultant
Consultant

@cyberflow  To minimize the amount of maintenance to PropertySet VBScript code I have devised a method which is working well in my initial testing. It involves having an Autoloader bundle which creates a new Sysvar "AECCVER" which is saved to the Registry and is accessible by all users on that computer. There is one entry per C3D Release in the PackageContents.xml file. Once the AECCVER Sysvar is set then the VBScript code never needs updating when using these PSet definitions:

2025-02-19_10-41-31.png

2025-02-19_10-42-12.png2025-02-19_10-42-31.png

2025-02-19_11-12-46.png

This is a portion of the PackageContents file for C3D 2023 & 2024:

 

  <Components Description="C3D 2023">
    <SystemVariables>
      <SystemVariable Flags="Create" Name="AECCVER" Owner="" PrimaryType="String" StorageType="User" Value="13.5"></SystemVariable>
    </SystemVariables>
    <RegistryEntries>
      <RegistryEntry Key="Variables\AECCVER" Value="13.5" Type="REG_SZ" Flags="Create|Open"></RegistryEntry>
    </RegistryEntries>
    <RuntimeRequirements OS="Win64" Platform="Civil3D" SeriesMin="R24.2" SeriesMax="R24.2" />
  </Components>
  <Components Description="C3D 2024">
    <SystemVariables>
      <SystemVariable Flags="Create" Name="AECCVER" Owner="" PrimaryType="String" StorageType="User" Value="13.6"></SystemVariable>
    </SystemVariables>
    <RegistryEntries>
      <RegistryEntry Key="Variables\AECCVER" Value="13.6" Type="REG_SZ" Flags="Create|Open"></RegistryEntry>
    </RegistryEntries>
    <RuntimeRequirements OS="Win64" Platform="Civil3D" SeriesMin="R24.3" SeriesMax="R24.3" />
  </Components>

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 18 of 32

Jeff_M
Consultant
Consultant

Attached is an autoloader bundle which creates the proper AeccVer sysvar for C3D2020-2025. This would be the only file that would need to be edited for future release support. I suggest placing the bundle in the C:\Program Files (x86)\Autodesk\ApplicationPlugins folder.

Jeff_M, also a frequent Swamper
EESignature
Message 19 of 32

Anton_Huizinga
Advocate
Advocate

That is a really cool trick! 

 

Edit: I've not tested yet, but what happens if you send the drawing to someone else without the bundle? Is the variable saved in the drawing as user variable?

0 Likes
Message 20 of 32

cyberflow
Advisor
Advisor

Awesome stuff @Jeff_M !

No worries, ill let you two talk and if i could wouldve brought you beers to listen both of you talk about this and learn !

Ill try to test that workflow

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes