Author Topic: Civil3D VBA - Excel Parcels  (Read 8736 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Civil3D VBA - Excel Parcels
« on: March 04, 2014, 08:39:50 AM »
I had a thought... I did not know how hard it was to create a VBA in excel that I could select an object (Civil3d Parcel) and extract or transfer the selected parcels to excel in someway? With that; I wonder if you could extract areas, parcel names, user fields, etc.

Thanks!
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer
Re: Civil3D VBA - Excel Parcels
« Reply #1 on: March 04, 2014, 08:54:51 AM »
The existing Parcel Reports in C3D can output to csv files for use in Excel. I suspect you are looking for something else?

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #2 on: March 04, 2014, 08:59:42 AM »
Nice. Can I customized the report (CSV) to pull user fields as well?
And of course the classic question. How can I get a command prompt to activate this?

I have a spreadsheet with custom buttons that the users can press to go through steps like a workflow. So If I can VBA the command from excel to cad. boom!
Autodesk Infrastructure Design Suite 2019

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #3 on: March 04, 2014, 09:11:22 AM »
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer
Re: Civil3D VBA - Excel Parcels
« Reply #4 on: March 04, 2014, 12:40:13 PM »
OK, if you are wanting to automate this from Excel, you'd probably have more luck coding it yourself using the API rather than sending commands for the reports. I'd try to help, but I haven't done any VBA coding in 6 years or more. And I'm not entirely sure how the C3D Interops might work outside of the Autocad environment. You might look at the sample files C3D ships with, there are still some for VBA.

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #5 on: March 06, 2014, 02:56:04 PM »
Jeff, RICVBA just left this post for excel VBA.

http://www.theswamp.org/index.php?topic=46487.new;topicseen#new

Is there away to get it to grab civil3d parcels?
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer
Re: Civil3D VBA - Excel Parcels
« Reply #6 on: March 06, 2014, 03:54:40 PM »
If you add a reference to the Aecc.Interop.Land & Aecc.Interop.UiLand you may be able to work with Parcels.

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #7 on: March 06, 2014, 04:02:03 PM »
Could I ask for an example? To me, the vba to excel makes sense. But how is that different from the VBA of civil3d?
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer
Re: Civil3D VBA - Excel Parcels
« Reply #8 on: March 06, 2014, 06:13:48 PM »
I can't believe I did this. Haven't worked in VBA in forever, only once before in Excel VBA, and yet this worked....
Code - vb.net: [Select]
  1. Sub PickLwPolyAndGetData()
  2.    
  3.     Dim MyCell As Range
  4.     Dim ACAD As AcadApplication
  5.     Dim LWPoly As AcadLWPolyline
  6.     Dim oParcel As AeccParcel
  7.     Dim ThisDrawing As AcadDocument
  8.     Dim Pt1 As Variant
  9.     Dim LWArea As Double, LWZ As Double
  10.  
  11.     ' Autocad Session handling
  12.     On Error Resume Next
  13.     Set ACAD = GetObject(, "AutoCAD.Application")
  14.     On Error GoTo 0
  15.     If ACAD Is Nothing Then
  16.         Set ACAD = New AcadApplication
  17.         ACAD.Visible = True
  18.     End If
  19.     Set ThisDrawing = ACAD.ActiveDocument
  20.          
  21.    
  22.     ' select LwPolyline
  23.     On Error Resume Next
  24.     Do
  25.         Err.Clear
  26.         ThisDrawing.Utility.GetEntity oParcel, Pt1, "Select a Parcel:"
  27.     Loop While Err
  28.     On Error GoTo 0
  29.    
  30.     'get LWPoly data
  31. '    With LWPoly
  32. '        LWArea = .Area
  33. '        LWZ = .Elevation
  34. '    End With
  35.    
  36.     'get oParcel data
  37.     With oParcel
  38.         LWArea = .Statistics.Area
  39.         LWZ = .Statistics.Perimeter
  40.     End With
  41.    
  42.     ' write LWPoly data on worksheet
  43.     Set MyCell = ActiveCell
  44.     With MyCell
  45.         .Offset(0, 0).Value = "Area:"
  46.         .Offset(0, 1).Value = LWArea
  47.         .Offset(1, 0) = "Perimeter:"
  48.         .Offset(1, 1) = LWZ
  49.     End With
  50.    
  51.     Set ThisDrawing = Nothing
  52.     Set ACAD = Nothing
  53.    
  54.  End Sub
  55.  
  56.  

As noted, need to add the correct references for your version, this shows them for 2013:

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #9 on: March 07, 2014, 07:13:00 AM »
You my man.... are awesome and so is Ricvba too for the idea... Way cool. Way cool! Cant wait to test this out.!
Autodesk Infrastructure Design Suite 2019

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #10 on: March 07, 2014, 08:12:13 AM »
Could you show me where all the i.e. (.Statistics.Area / .Statisitics.Perimter) are located or what they are called if I am looking for (Description / User Defined Properties [Unclassified] {User1} {User2} {User3})

Those User1, 2, 3 are custom fields that we manually place in the parcel.
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #12 on: March 07, 2014, 10:22:53 AM »
I have found the link for the User Data;

http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccParcel__SetUserDefinedPropertyValue@[in]_VARIANT@[in]_VARIANT.htm

Code: [Select]
I would like to replace the [code]LWArea = .Statistics.Perimeter
to

Code: [Select]
[ id(AECCXLAND_DISPID_PARCEL_SETUSERDEFINEDPROPERTYVALUE), helpcontext(IDH_AECCXLAND_PARCEL_SETUSERDEFINEDPROPERTYVALUE), helpstringcontext(AECCXLAND_HELPSTR_PARCEL_SETUSERDEFINEDPROPERTYVALUE) ]
HRESULT SetUserDefinedPropertyValue(
    [in] VARIANT userDefinedProperty,
    [in] VARIANT newValue
);

I am not sure how to place this in the above code.
Autodesk Infrastructure Design Suite 2019

MSTG007

  • Water Moccasin
  • Posts: 2414
  • I can't remeber what I already asked! I need help!
Re: Civil3D VBA - Excel Parcels
« Reply #13 on: March 07, 2014, 10:37:54 AM »
I think I gave the wrong code above.

docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccParcel__GetUserDefinedPropertyValue@[in]_VARIANT@[out,_retval]_VARIANT_.htm

Code: [Select]
[ id(AECCXLAND_DISPID_PARCEL_GETUSERDEFINEDPROPERTYVALUE), helpcontext(IDH_AECCXLAND_PARCEL_GETUSERDEFINEDPROPERTYVALUE), helpstringcontext(AECCXLAND_HELPSTR_PARCEL_GETUSERDEFINEDPROPERTYVALUE) ]
HRESULT GetUserDefinedPropertyValue(
    [in] VARIANT userDefinedProperty,
    [out, retval] VARIANT* pVal
);
Autodesk Infrastructure Design Suite 2019

Jeff_M

  • King Gator
  • Posts: 3963
  • C3D user & customizer
Re: Civil3D VBA - Excel Parcels
« Reply #14 on: March 07, 2014, 11:00:51 AM »
Code - vb.net: [Select]
  1. Dim User1 As Variant
  2.     With oParcel
  3.         LWArea = .Statistics.Area
  4.         LWZ = .Statistics.Perimeter
  5.         User1 = .GetUserDefinedPropertyValue("User1")
  6.     End With
  7.  

Note that if the Parcel doesn't have this UDP assigned to it this will throw an error, so be sure to trap for it.