Author Topic: VBA C3D 2011 Align by polyline select on screen  (Read 7652 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
VBA C3D 2011 Align by polyline select on screen
« on: February 27, 2011, 01:05:07 PM »

Need some help adding an alignment in 2011 by polyline select on screen.
Routine crashs setting AlignmentStyles.Item(0) and.AlignmentLabelStyleSets.Item(0)
I have styles and label style sets in the drawing. I thought .item (0) would get first alignment style and label set

Goal is to create and draw alignment that is not part of a site by selecting an existing polyline.

Thanks for any hints, links

John Coon


Private Sub CommandButton4_Click()

UserForm1.hide
'Public g_oCivilApp As AeccApplication
'Public g_oDocument As AeccDocument
'Public g_oAeccDatabase As AeccDatabase

Dim AlignmentsSiteless As AeccAlignmentsSiteless
Dim Alignment As AeccAlignments
Dim Align As AeccAlignment
Dim AlignmentStyle As AeccAlignmentStyle
Dim AlignmentLabelStyleSet As AeccAlignmentLabelStyleSet

Set AlignmentStyle = g_oDocument.AlignmentStyles.Item(0)
'"_Proposed"
Set AlignmentLabelStyleSet = g_oDocument.AlignmentLabelStyleSets.Item(0)
'("_No Labels")

Dim sAlignName As String
Dim sLayerName As String
     
Dim oPoly As AcadLWPolyline
Dim pt As Variant
Dim obj As AcadObject
ThisDrawing.Utility.GetEntity obj, pt, "Select the Polyline to convert to an Alignment :"

If TypeOf obj Is AcadLWPolyline Then
Set oPoly = obj
Else
MsgBox "Selected Entity is NOT a Pline ! "
End If
       
Dim dPolyObjId As Long
dPolyObjId = oPoly.ObjectID
       

sAlignName = "UsingTheAddFromPolylineMethod"
sLayerName = "0"
           
Set Alignment = oAlignmentsSiteless.Add(sAlignName, sLayerName, AlignmentStyle, AlignmentLabelStyleSet)
AlignmentsSiteless.AddFromPolyline sAlignName, sLayerName, dPolyObjId, AlignmentStyle, AlignmentLabelStyleSet, True, True
   
 'not sure what else.....

UserForm1.Show


End Sub

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #1 on: February 27, 2011, 09:18:15 PM »
This worked for me in 2010, John. I don't/won't have VBA installed for 2011....heard it slows down too much on the 64-bit version so no VBA for me.

Code: [Select]
Public Sub aligntest()

    If (GetCivilObjects() = False) Then
        MsgBox "Error accessing Civil 3D!"
        Exit Sub
    End If

Dim AlignmentsSiteless As AeccAlignmentsSiteless
Dim Alignment As AeccAlignments
Dim Align As AeccAlignment
Dim AlignmentStyle As AeccAlignmentStyle
Dim AlignmentLabelStyleSet As AeccAlignmentLabelStyleSet

Set AlignmentStyle = g_oDocument.AlignmentStyles.Item(0)
'"_Proposed"
Set AlignmentLabelStyleSet = g_oDocument.AlignmentLabelStyleSets.Item(0)
'("_No Labels")

Dim sAlignName As String
Dim sLayerName As String
     
Dim oPoly As AcadLWPolyline
Dim pt As Variant
Dim obj As AcadObject
ThisDrawing.Utility.GetEntity obj, pt, "Select the Polyline to convert to an Alignment :"

If TypeOf obj Is AcadLWPolyline Then
Set oPoly = obj
Else
MsgBox "Selected Entity is NOT a Pline ! "
End If
       
Dim dPolyObjId As Long
dPolyObjId = oPoly.ObjectID
       

sAlignName = "UsingTheAddFromPolylineMethod"
sLayerName = "0"
           
Set Align = g_oDocument.AlignmentsSiteless.AddFromPolyline(sAlignName, sLayerName, dPolyObjId, AlignmentStyle, AlignmentLabelStyleSet, True, True)
   
End Sub

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #2 on: February 28, 2011, 08:56:39 AM »
Jeff,

This is strange, I ran your sample and it work like a charm. I paste the same code to a button in the same project add userform hide and show
and I get an error here: Set AlignmentStyle = g_oDocument.AlignmentStyles.Item(0), same as before.

Thanks for your help........I do some checking in different versions, this was to be a half hour project for labeling some marking and it turned out to be more than that.

vba, I'm still working on dot net, it's getting better but I thought this was going to a simple task in vba, faster and it turned out I might of tried it dot given the amout of time I was working on it.

John 

 


Private Sub CommandButton3_Click()
UserForm1.Hide
 
 If (GetCivilObjects() = False) Then
        MsgBox "Error accessing Civil 3D!"
        Exit Sub
    End If

Dim AlignmentsSiteless As AeccAlignmentsSiteless
Dim Alignment As AeccAlignments
Dim Align As AeccAlignment
Dim AlignmentStyle As AeccAlignmentStyle
Dim AlignmentLabelStyleSet As AeccAlignmentLabelStyleSet

Set AlignmentStyle = g_oDocument.AlignmentStyles.Item(0)
'"_Proposed"
Set AlignmentLabelStyleSet = g_oDocument.AlignmentLabelStyleSets.Item(0)
'("_No Labels")

Dim sAlignName As String
Dim sLayerName As String
     
Dim oPoly As AcadLWPolyline
Dim pt As Variant
Dim obj As AcadObject
ThisDrawing.Utility.GetEntity obj, pt, "Select the Polyline to convert to an Alignment :"

If TypeOf obj Is AcadLWPolyline Then
Set oPoly = obj
Else
MsgBox "Selected Entity is NOT a Pline ! "
End If
       
Dim dPolyObjId As Long
dPolyObjId = oPoly.ObjectID
       

sAlignName = "UsingTheAddFromPolylineMethod"
sLayerName = "0"
           
Set Align = g_oDocument.AlignmentsSiteless.AddFromPolyline(sAlignName, sLayerName, dPolyObjId, AlignmentStyle, AlignmentLabelStyleSet, True, True)

UserForm1.Show
   
End Sub

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #3 on: February 28, 2011, 10:54:13 AM »
Can you post the DVB John? I just created a new project, added a form with 3 buttons, used this code, and it worked fine.

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #4 on: February 28, 2011, 12:16:21 PM »
Jeff,

here is the dwg I was using. your sample is in module2, I pasted that into button and got the error.

john

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #5 on: February 28, 2011, 12:17:15 PM »
Sorry missed the vba sample

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #6 on: February 28, 2011, 12:22:46 PM »

Jeff,

I get the erroe becuase I had this loaded in the general declarations.

Option Explicit

Public g_oCivilApp As AeccApplication
Public g_oDocument As AeccDocument
Public g_oAeccDatabase As AeccDatabase
Public g_oExcelBook As Workbook
Public g_oExcelApp As Excel.Application

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #7 on: February 28, 2011, 07:00:07 PM »
Does that mean it now works?

I see a major problem if you plan to be working with alignments.....you are using this for your InterfaceObject:

"AeccXUiRoadway.AeccRoadwayApplication.6.0"

First, 2011 uses the 8.0 version, not 6.0. But, more importantly, the Roadway application is for corridor objects. You need the AeccXUiLand.AeccApplication for the base objects.

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #8 on: February 28, 2011, 07:06:01 PM »
Question:

Why not simply use the Create Alignment from Object command that already exists inside C3D and select your polyline at the command prompt to do so?

You can do this AND not have the resulting alignment be part of any site.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #9 on: March 01, 2011, 07:56:38 AM »
Jeff, Higgs

Yes it works fine now. I just need to add something to save or delete the existing polyline.
 "AeccXUiRoadway.AeccRoadwayApplication.6.0" is what I was using at work, "AeccXUiRoadway.AeccRoadwayApplication.8.0" is what I was using at home sorry
 
when I change from AeccXUiRoadway.AeccRoadwayApplication to AeccXUiLand.AeccApplication I now get an error. I'll check during lunch to see if I can fix that.

Higgs,
I know I can create an alignment from a polyline,  it's drawing the painted dashed edge stripes and getting the station offset layout for the contractor from and existing alignment saved to excel or cvs or create from existing polyline. It's a quick routine for marking dashed centerline edge stripes . the final gets all the centerline polys on a specific layer creates the alignments, draws the markings and in the end deletes the new alignment. or it will get all the selected alignments and do the same without deleting the alignment.

I'm not putting that much into anything new in VBA until I can get dot net working for me.  I know I need spend more time in dot net however it's difficult when you know in a few hours with VBA I can get SOMETHING that I can work with and in dot net that might take me a week.

Thanks as always Jeff.

John

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #10 on: March 01, 2011, 08:13:03 AM »
If I understand what you are doing, OFFSET alignments made directly from the Design centerline would accomplish the same end state.
No trip through CSV, or need to draw new polylines. I used to use a similar process for lane markings with Land Desktop. I would have to see the process in use, however I can imagine some production gains through your method.


Thanks for taking the time to illuminate me on this.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #11 on: March 02, 2011, 12:30:06 PM »
Higgs,

I couldn't think of a way to control the spacing with the alignment. if it was simple graphic I guess I could make the offset alignments linetype hidded but I need to have stripes 9 foot long with a 3 foot space ending in a 6 foot stripe. could I do that using your method? I guess I can't see how.

as for the CSV / excel that is what we give the contractor for layout. we don't supply a table in the dwg for marking curve data in these cases.

John

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #12 on: March 02, 2011, 12:52:10 PM »
Higgs,

I couldn't think of a way to control the spacing with the alignment. if it was simple graphic I guess I could make the offset alignments linetype hidded but I need to have stripes 9 foot long with a 3 foot space ending in a 6 foot stripe. could I do that using your method? I guess I can't see how.

as for the CSV / excel that is what we give the contractor for layout. we don't supply a table in the dwg for marking curve data in these cases.

John

I haven't tested this with C3D....however one could potentially create the dashed pattern you describe using a combination of Label Set for the Start end segment of 6') and Linetype (that you create) being applied to the alignment(s) for the normal dash pattern.
 Could be one might need add segments to the alignment(s) to force the LTGEN to dash as desired....
Let me explore that a little and comment back here.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

jcoon

  • Newt
  • Posts: 157
Re: VBA C3D 2011 Align by polyline select on screen
« Reply #13 on: March 03, 2011, 09:22:16 AM »
Higgs,

If you come up with a method to do that I'd be interested but It also seems like a lot of work to get it so the spacing would work at any scale

John