Wednesday 29 August 2012

Code to Name Parcels after selected discharging Structure

Last week I wanted some code to quickly add a user property to a Parcel label to display what structure its flow was discharging too. I tried accessing user defined properties from the API but had no luck and requested an example form the ADN team which Partha posted here.

Seeing the job had to out the door, I wrote this code in the interim to use the Parcel Name and just add a counter on the end to avoid having Parcel name double ups which are not allowed.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput

'Civil3d Com Imports
Imports AeccLandLib = Autodesk.AECC.Interop.Land

'Civil3d Imports
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.AECC.Interop.Land
Imports Autodesk.AutoCAD.Interop




Public Class ConnectParceltoStructure


<CommandMethod("xpConnectParceltoStructure")> _
Public Sub ConnectParceltoStructure()
Dim document As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = document.Editor
Dim db As Database = document.Database

Dim peo1 As New PromptEntityOptions(vbLf & "Select Catchment Parcel : ")

peo1.SetRejectMessage(vbLf & "Invalid selection...")
peo1.AddAllowedClass(GetType(Autodesk.Civil.Land.DatabaseServices.Parcel), True)

Dim pEntrs As PromptEntityResult = ed.GetEntity(peo1)
If PromptStatus.OK <> pEntrs.Status Then
Return
End If

Dim
ParcelId As ObjectId = pEntrs.ObjectId

Dim peo2 As New PromptEntityOptions(vbLf & "Select Structure to Link to : ")

peo2.SetRejectMessage(vbLf & "Invalid selection...")
peo2.AddAllowedClass(GetType(Autodesk.Civil.PipeNetwork.DatabaseServices.Structure), True)

pEntrs = ed.GetEntity(peo2)
If PromptStatus.OK <> pEntrs.Status Then
Return
End If

Dim
StructureId As ObjectId = pEntrs.ObjectId

Try
Using
trans As Transaction = db.TransactionManager.StartTransaction()
Dim oParcel As Autodesk.Civil.Land.DatabaseServices.Parcel = TryCast(trans.GetObject(ParcelId, OpenMode.ForRead), Entity)
Dim oStructure As Autodesk.Civil.PipeNetwork.DatabaseServices.Structure = TryCast(trans.GetObject(StructureId, OpenMode.ForRead), Entity)

oParcel.UpgradeOpen()


Dim StructureName As String = oStructure.Name

Dim ParcelDischargeStructure As String = oParcel.Name

'Check the all the Parcel Names in the site to see if name already exists
'if it does add counter to the end of name


Dim Count As Integer = 1
Dim x As String = "Writing"
Dim NewParcelName As String = StructureName

'Change the Parcel Name to the Structure Name
Do Until IsNothing(x)
Try
oParcel.Name = NewParcelName

'We have gotten to this line without firing an exception
' therefore written the structure name to the Parcel name set x to nothing to exit loop
x = Nothing

Catch
ex As System.Exception
'MsgBox("Error " & Err.Description & " - " & Err.Number & Convert.ToChar(10))
NewParcelName = StructureName & ("-(" & Count & ")")
Count = Count + 1
'Return
End Try


Loop

trans.Commit()
End Using
Catch
ex As System.Exception
ed.WriteMessage(ex.Message)
End Try
End Sub

End Class

Tuesday 28 August 2012

Sheet Set Manager – Updating Existing Title block Fields

Just had to change a number of fields in an existing title block to be sheet specific instead sheetset specific to allow different Draught people and Designer initials per sheet for a large project.

The process of creating the custom fields in your sheetset file is cover here but in summary :-

tr53mkng

fnstd0id

Once you have the new custom fields you have to use the enhanced Block editor with the EATTEDIT command and remap to the new fields to the correct location.

1avznaal

Now in Sheetset manager under each sheet you have a place to enter the Designer and Drawer. The way Sheet Manger is setup to access this data is a dog so an investment in a 3rd party app like JTB World’s SSMPropEditor is worth while

50ryjy3hytpa3d4m

The major issue you have with this process is it does not update already existing blocks so you have to do each one manually.There is some more discussion here on the issue and Shane at Between the line suggests a method here of exploding the existing block, which I was not able to get to update existing blocks either.

If anyone knows a better method I would be interested to hear about it as I am sure this will not be the last time I have to do this.

Monday 27 August 2012

SSA Custom Report Gotcha

Seeing SSA does not do a Cole-Brook White analysis we have to dump everything to a spreadsheet to do this. To get the pipe data out I have a custom report in SSA that gives me the columns of data I require. (Use to have VBA code but have not had time to updated it).

However when I initial tried to setup a excel spreadsheet to do a sumif on the parcel catchment data it did not find a match. I found the issue to be that SSA includes a funny character that you can not see in its output to excel. To clear it from the excel output from SSA I have to save a csv file and then re import it to Excel. This displays the characters then you can do a find replace to remove them.

dreqbbgl

 

tktwpngp

 

 

grbyiq1u

Monday 20 August 2012

Managing Superseded and Revised Drawings

Currently we do not use a database system like Vault or Project Wise to manage project superseded and revised drawings. Typically we just have a superseded file in the same folder as the production drawing and transfer a copy of a drawing to that folder prior to revising it for whatever reason.
Some times however I forget to make a backup copy of the drawing to the superseded folder. To over come this I put some code together the other day to prompt the user on opening of a drawing weather or not to create a copy to the superseded folder . Here is  dump  of the code that others may find helpful. Currently I append the current date and time to the file name but am looking at prompting for a revision letter or the like.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports System Imports System.IO Public Class Class4 Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Private docMan As DocumentCollection = Application.DocumentManager <CommandMethod("AddDocColEvent")> _ Public Sub Initialize() Implements IExtensionApplication.Initialize AddHandler docMan.DocumentCreated, AddressOf docMan_DocumentCreated DoIt() End Sub <CommandMethod("RemoveDocColEvent")> _ Public Sub RemoveDocColEvent() RemoveHandler docMan.DocumentCreated, AddressOf docMan_DocumentCreated End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate End Sub Sub docMan_DocumentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) DoIt() End Sub Private Sub DoIt() 'check if the drawing has been saved yet or not Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim strDWGName As String = acDoc.Name Dim obj As Object = Application.GetSystemVariable("DWGTITLED") '' Check to see if the drawing has been named If System.Convert.ToInt16(obj) = 0 Then '' If the drawing is using a default name (Drawing1, Drawing2, etc) '' then do nothing Else 'Ask the user if they want to save a supercended version of this drawing Dim Message As String Message = "Save a Superseded version of this drawing." Dim style = MsgBoxStyle.YesNoCancel Or MsgBoxStyle.DefaultButton1 Or MsgBoxStyle.Critical Dim Title As String Title = "Supercended" ' Display the message box and save the response, Yes or No. Dim response = MsgBox(Message, style, Title) Select Case response Case 6 ' Yes 'Get the current drawings path ' Specify the directories you want to manipulate. Dim path As String = DrawingPath() Dim Directory As String = Application.GetSystemVariable("DWGPREFIX") & "Superseded\" 'Ask the user if they want to add a suffix or prefix to the file name ''Dim FormToOpen As Type ''FormToOpen = GetType(Form1) ''Dim frm As Form1 = CType(Activator.CreateInstance(FormToOpen), Form1) ''Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm) Dim time As DateTime = DateTime.Now Dim format As String = "yy.MM.dd.HH.mm" Dim timestring As String = (time.ToString(format)) Dim path2 As String = Directory & timestring & "_" & Application.GetSystemVariable("DWGNAME") 'Check for the supercended folder in the current drawing path 'Create directory Try If (Not System.IO.Directory.Exists(Directory)) Then System.IO.Directory.CreateDirectory(Directory) End If 'Save a copy of the current drawing ' Copy the file. File.Copy(path, path2) Catch ex As System.Exception MsgBox("Error " & Err.Description & " - " & Err.Number & Convert.ToChar(10)) Return End Try Case 7 'No 'Do Nothing Case 2 'Cancel 'Do Nothing Case Else MsgBox("Response not recongised") End Select End If End Sub Public Function DrawingPath() As String Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim hs As HostApplicationServices = HostApplicationServices.Current Dim path As String = hs.FindFile(doc.Name, doc.Database, FindFileHint.[Default]) 'doc.Editor.WriteMessage(vbLf & "File was found in: " & path) Return path End Function End Class

Thursday 16 August 2012

Dropbox and Sheetset .dst files

Been working with a project team through Dropbox, just something you need to be aware of with Autocad and sheetsets is the setting SSMAUTOOPEN .
Your team should all have SSMAAUTOOPEN set to 0. or when anyone on the team  opens a drawing linked into the sheetset .dst it will open  and it maybe already opned by ours others and dropbox will get a load of conflicting .dst files.

Wednesday 15 August 2012

Using MapBookCreate to create plan sheet layouts

I while ago I mentioned the location where you can find the Mapbook Templates and the location of the online tutorials to set up your own template based on the shipped template.

Once you have setup your template you can use the Map command “MapBookCreate” to layout your plan sheets to cookie cut up a large sites that will not fit on one sheet.

Once you type the MapBookCreate the following wizard is started

1. First give the map book a name such as the discipline. The mapbookname will be added to the start of the name of each layout created and added to the drawing. i.e Roading-XXXXX
mt1jeqlx 
2.Next browse to your sheet template.
bd2fptk5

3.Now setup your tiling scheme. I usually have zero percentage of overlap.
.wcifaqhk
4. Setup your Layout Naming Scheme
i1mut0vm
5. Now you can setup a key and legend if you want from layers in the drawing. I typically do not use these settings.
6. Next you can add the layouts you are going to create to a sheetset.

nagyile3

7. Now you can preview the sheet layout
gldeellr
8. And if happy generate the layout sheets
c3xqkboa
9. If you have keep the “Adjacent arrows blocks” in you template you can hold the Ctrl key and click the “Adjacent arrows blocks” to jump to the appropriate numbered layout sheet from within each layout.
cvedxfxw

Tuesday 7 August 2012

Using Alignments & Profiles to mimic standalone Sections

For a while now I have been using Alignments and Profiles to mimic individual section lines through sites when multiple sections are overkill.
53mlelto
I have always had an issue with labelling the key crossing points of featurelines or other key lines in the profile or section bands.

Coincidently Peter Thompson and myself were having a discussion offline on the subject of section labelling a while ago, but we did not get very far so Peter posted the subject in the civil3d forums here. Where Tim suggested using sections made from polylines that has vertices points at each intersection point that is to be labelled.
 
The same principle works for Alignments as well by adding a horizontal geometry points at the crossing line intersections.
bkm0nz0f
And then turning the display options on for the profile view and bands.
jhwv0npy
 
To speed up the process of adding the intersecting vertices to a polyline (to then converting it to an alignment), I have been looking for a built in function in Autocad to do the job but have had no luck. I did find find this utility here that does it.
Related Posts Plugin for WordPress, Blogger...