Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating an alignment with VBA

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
1001 Views, 7 Replies

Creating an alignment with VBA

I'm looking for an example that shows how to create a simple alignment (two tangents and a curve) via code. Creating the tangents and adding a curve using the .AddFreeXXX, .AddFloatingXXX, .AddFixedXXX methods offer more flexibility than creating an alignment from a polyline (see my previous post). Any help is greatly appreciated... Thanks, Scott
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Hi Scott, As far as I can see, you will be able to do this when the programming APIs work. In the meantime I haven't been able to do anything but create an alignment by polyline with all the grip editing limitations of that type of alignment. Hopefully I'm just ignorant and there is a way. -- Regards, Laurie Comerford www.cadapps.com.au "Scott" wrote in message news:41fdb9f0_1@newsprd01... > I'm looking for an example that shows how to create a simple alignment > (two tangents and a curve) via code. Creating the tangents and adding a > curve using the .AddFreeXXX, .AddFloatingXXX, .AddFixedXXX methods offer > more flexibility than creating an alignment from a polyline (see my > previous post). > > Any help is greatly appreciated... > Thanks, > Scott > > > >
Message 3 of 8
Anonymous
in reply to: Anonymous

Here are the guts of that code, it assumes that you have: alignment style alignment Label Style Start point, ip point, end point Radius (Watch the word wrap) Set align = cAligns.Add("SampleAlignment", "0", alignStyle, alignLabelStyleSet) Set cEnts = align.Entities Set aTan1 = cEnts.AddFixedLine1(spt, ip1) Set aTan2 = cEnts.AddFixedLine1(ip1, ept) Set aEnt = cEnts.AddFreeCurve1(aTan1.Id, aTan2.Id, aeccFreeCurveConstraintRadius, radius, False,aeccFloatingCurveIsCompound) Cheers, Peter Funk API Product Manager Autodesk, Inc.
Message 4 of 8
Anonymous
in reply to: Anonymous

Thanks, Peter. Here's what I have but it won't run. I get a message that says "Object variable or With block not set". Any suggestions? Thank, Scott Private Sub CreateAlignment() Dim cAligns As AeccAlignments Dim oAlign As AeccAlignment Dim cEnts As AeccAlignmentEntities Dim aTan1 As AeccAlignmentTangent Dim aTan2 As AeccAlignmentTangent Dim aEnt As AeccAlignmentEntity Dim spt(0 To 1) As Double Dim ip1(0 To 1) As Double Dim ept(0 To 1) As Double Dim Radius As Double Dim alignStyle As String Dim alignLabelStyleSet As String Radius = 500 spt(0) = 385899.54: spt(1) = 639003.43 ip1(0) = 388137.05: ip1(1) = 640497.22 ept(0) = 392663.65: ept(1) = 644654.26 Set oAlign = cAligns.Add("SampleAlignment", "0", alignStyle, alignLabelStyleSet) Set cEnts = oAlign.Entities Set aTan1 = cEnts.AddFixedLine1(spt, ip1) Set aTan2 = cEnts.AddFixedLine1(ip1, ept) Set aEnt = cEnts.AddFreeCurve1(aTan1.Id, aTan2.Id, aeccFreeCurveConstraintRadius, Radius, False, aeccFloatingCurveIsCompound) End Sub
Message 5 of 8
Anonymous
in reply to: Anonymous

I'm pretty sure you'll have to fill in the String value for AlignLabelStyleSet. You can use "Standard" and be pretty safe. In some work here, I've just placed "STANDARD" in the code to avoid using a variable. Won't swear you have to define it, but it's a guess. -- James Wedding, P.E. Technology Manager & Associate Jones & Boyd, Inc. Dallas, TX XP/2 on P4-3.4/1G LDT2005SP1 & C3D2005SP1
Message 6 of 8
Anonymous
in reply to: Anonymous

Thanks for pointing that out, James. I tried using string variables and placing the names directly in the line of code (no variables) but this does not appear to be source of the problem. I also tried setting the object variables to Nothing before the end of the function but that didn't help either. I'll keep searching for soemthing... Thanks, Scott "James Wedding" wrote in message news:41fe651f_3@newsprd01... > I'm pretty sure you'll have to fill in the String value for > AlignLabelStyleSet. You can use "Standard" and be pretty safe. In some > work here, I've just placed "STANDARD" in the code to avoid using a > variable. > > Won't swear you have to define it, but it's a guess. > > -- > James Wedding, P.E. > Technology Manager & > Associate > Jones & Boyd, Inc. > Dallas, TX > XP/2 on P4-3.4/1G > LDT2005SP1 & C3D2005SP1 >
Message 7 of 8
Anonymous
in reply to: Anonymous

Public g_oCivilApp As AeccApplication Public g_oAeccDoc As AeccDocument Public g_oAeccDb As AeccDatabase Function getCivilObjects() As Boolean Dim oApp As AcadApplication Set oApp = ThisDrawing.Application Const sAppName = "AeccXUiLand.AeccApplication" Set g_oCivilApp = oApp.GetInterfaceObject(sAppName) If g_oCivilApp Is Nothing Then MsgBox "Error creating " & sAppName & ", exit." getCivilObjects = False Exit Function End If Set g_oAeccDoc = g_oCivilApp.ActiveDocument Set g_oAeccDb = g_oAeccDoc.Database getCivilObjects = True End Function inside your subroutine: Dim alignStyle As AeccAlignmentStyle Dim alignLabelStyleSet As AeccAlignmentLabelStyleSet Dim site As AeccSite Dim cAligns As AeccAlignments Set cSites = g_oAeccDb.sites If cSites.Count = 0 Then Set site = cSites.Add("Site 1") Else Set site = cSites.Item(0) End If Set cAligns = site.Alignments Set align = cAligns.Add("SampleAlignment", "0", alignStyle, alignLabelStyleSet) Set alignStyle = g_oAeccDb.AlignmentStyles.Item(0) Set alignLabelStyleSet = g_oAeccDb.AlignmentLabelStyleSets.Item(0) That should do it... Peter
Message 8 of 8
Anonymous
in reply to: Anonymous

That was a BIG help! Thanks, Peter. I knew I had to get the civil objects and define the public variables but when I copied the code to a seperate project so I could figure out why it wasn't working, I forgot to copy those pieces. Plus, I needed to declare the PI points as arrays which include the Z value, not just X & Y. Thanks, Scott "Peter Funk - Autodesk, Inc." wrote in message news:41fe9f4e$1_3@newsprd01... > Public g_oCivilApp As AeccApplication > Public g_oAeccDoc As AeccDocument > Public g_oAeccDb As AeccDatabase > > Function getCivilObjects() As Boolean > Dim oApp As AcadApplication > Set oApp = ThisDrawing.Application > Const sAppName = "AeccXUiLand.AeccApplication" > Set g_oCivilApp = oApp.GetInterfaceObject(sAppName) > If g_oCivilApp Is Nothing Then > MsgBox "Error creating " & sAppName & ", exit." > getCivilObjects = False > Exit Function > End If > Set g_oAeccDoc = g_oCivilApp.ActiveDocument > Set g_oAeccDb = g_oAeccDoc.Database > getCivilObjects = True > End Function > > inside your subroutine: > Dim alignStyle As AeccAlignmentStyle > Dim alignLabelStyleSet As AeccAlignmentLabelStyleSet > Dim site As AeccSite > Dim cAligns As AeccAlignments > Set cSites = g_oAeccDb.sites > If cSites.Count = 0 Then > Set site = cSites.Add("Site 1") > Else > Set site = cSites.Item(0) > End If > Set cAligns = site.Alignments > Set align = cAligns.Add("SampleAlignment", "0", alignStyle, > alignLabelStyleSet) > Set alignStyle = g_oAeccDb.AlignmentStyles.Item(0) > Set alignLabelStyleSet = g_oAeccDb.AlignmentLabelStyleSets.Item(0) > > That should do it... > > Peter > >

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report