Manipulate offset profile parameters

Manipulate offset profile parameters

serpetfree
Contributor Contributor
658 Views
4 Replies
Message 1 of 5

Manipulate offset profile parameters

serpetfree
Contributor
Contributor

I'm trying to manipulate offset profile parameters. But nothing happens.
I can read offset profile parameters, but I can't write or remove.

I have Civil 3D 2022.1.1 Update.

I'm not sure I'm using it right, I don't know what I'm doing wrong, I'm trying 3 different ways. Why doesn't any of them work?

Here is my code snippet VB .NET:

 

 

Dim docCol As Autodesk.AutoCAD.ApplicationServices.DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
        Dim db As Database = docCol.MdiActiveDocument.Database

        Dim tr As Transaction = db.TransactionManager.StartTransaction()
        Dim ln As Long
        Dim lnProf As Long
        Dim id As ObjectId
        Dim idProf As ObjectId
        
        ln = Convert.ToInt32(alignmentHANDLE, 16)
        lnProf = Convert.ToInt32(profileHANDLE, 16)

        Dim hn As New Handle(ln)
        Dim hnProf As New Handle(lnProf)
    
            id = db.GetObjectId(False, hn, 0)
            Dim pl As Alignment = tr.GetObject(id, OpenMode.ForWrite) 'get offset alignmet

            idProf = db.GetObjectId(False, hnProf, 0)
            Dim plProf As Profile = tr.GetObject(idProf, OpenMode.ForWrite) 'get offset profile

            Dim staDouble As Double
            Dim slopeDouble As Double

            staDouble = 600
            slopeDouble = 0.05

            Dim Prof_Parameters As New Profile.OffsetProfileParameters(plProf)
            Dim Param_station As New Profile.OffsetProfileParametersStation(staDouble, slopeDouble, "test1")

            'method 1
            Prof_Parameters.Stations.Add(Param_station)
            'method 2
            Prof_Parameters.Stations.Insert(Prof_Parameters.Stations.Count, Param_station)

            'method 3
            staDouble = 700
            slopeDouble = 0.05
            Param_station.Station = staDouble
            Param_station.Slope = slopeDouble
            Param_station.Description = "test2"

            plProf.OffsetParameters.Stations.Add(Param_station)

            tr.Commit()
            tr.Dispose()

 

0 Likes
Accepted solutions (1)
659 Views
4 Replies
Replies (4)
Message 2 of 5

hosneyalaa
Advisor
Advisor
0 Likes
Message 3 of 5

serpetfree
Contributor
Contributor

Thank you I have seen this page, but it's not working for me, I don't know.

 

plProf is Profile
Param_station is Profile.OffsetProfileParametersStation

 

But this is not working:
plProf.OffsetParameters.Stations.Add(Param_station)

In my visual studio :
ReadOnly Property Profile.Offsetparameters As Profile.OffsetProfileParameters

I don't understand.

 

I've attached a Visual Studio printscreenReadOnly.jpg

 

0 Likes
Message 4 of 5

hosneyalaa
Advisor
Advisor
Accepted solution

 

can you read this is

but it is Python Script node

 

https://forum.dynamobim.om/t/superelevation-to-offset-profile/65767/5

 

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('Civil3DNodes')
clr.AddReference('System')

from System.Collections.Generic import List

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# Import references for Dynamo for Civil 3D
from Autodesk.Civil.DynamoNodes import Alignment as DynAlignment

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument

align = IN[0]
station = IN[1]
slope = IN[2]

result = []
oppsset = []

def offsetsuper(align,station,slope):
	global adoc
	global editor
	global civdoc
	
	try:	
		with adoc.LockDocument():
			with adoc.Database as db:
				with db.TransactionManager.StartTransaction() as t:
					#Selected alignment ID and object			
					alignment = align
					alignmentId = alignment.InternalObjectId
					al = t.GetObject(alignmentId, OpenMode.ForRead)
					alname = al.Name
					#Profile ID and object
					profileId = al.GetProfileIds()[0]
					profile = t.GetObject(profileId, OpenMode.ForWrite)
					profilename = profile.Name
					#get and clear existing parameters
					opp = profile.OffsetProfileParameters(profile)
					oppstations = opp.Stations
					oppstations.Clear()
					n = station.Count
					for i in range(0,n):
						slopepercent = slope[i]*0.01
						opps = profile.OffsetProfileParametersStation(station[i],slopepercent)
						oppsset.append(opps) 
					oppssetlist = List[Profile.OffsetProfileParametersStation](oppsset)
					opp.Stations = oppssetlist
					oppstations = opp.Stations
					#a = opp.Stations
					t.Commit()

	except Exception() as ex:
		oppstations.append(ex.message)
	return oppstations

# Assign your output to the OUT variable.
OUT = offsetsuper(align,station,slope)

 

Message 5 of 5

serpetfree
Contributor
Contributor

Thanks for your help, problem solved.