- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Projekt Geometry by creating a Sketch on a View in .idw file.?
I am new in VBA coding, and I would like help from community.
I need a vba or i logic code, to project selected view onto created Sketch and offset it by 5-10 mm. I wanted to automate it a little bit . Can some one help me pls .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @b.kushaiynov. Even though this task seems simple, it is a bit more complicated to get working than it seems. It is fairly easy to create the sketch, and project the geometry, but creating the offset geometry is the tricky part. Below is some iLogic code to get you started. But it was throwing an error in my brief testing for some reason at the line of code which calls the main method (OffsetSketchEntitiesUsingDistance).
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub
Dim oDDoc As DrawingDocument = oView.Parent.Parent
Dim oTrans = ThisApplication.TransactionManager.StartTransaction(oDDoc, "View Sketch")
Dim oDCurves As DrawingCurvesEnumerator = oView.DrawingCurves
Logger.Info("oDCurves.Count = " & oDCurves.Count)
If oDCurves Is Nothing OrElse oDCurves.Count = 0 Then Exit Sub
Dim oDSketch As DrawingSketch = oView.Sketches.Add
Dim oSEsColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDCurve As DrawingCurve In oDCurves
Dim oPSE As SketchEntity = oDSketch.AddByProjectingEntity(oDCurve)
'Logger.Info("TypeName(oPSE) = " & TypeName(oPSE))
oSEsColl.Add(oPSE)
Next 'oDCurve
Logger.Info("oSEsColl.Count = " & oSEsColl.Count)
Dim oSEE As SketchEntitiesEnumerator = Nothing
Try
oSEE = oDSketch.OffsetSketchEntitiesUsingDistance(oSEsColl, 5, True)
oTrans.End
Catch e As Exception
Logger.Error(e.Message & vbCrLf & e.StackTrace)
oTrans.Abort
End Try
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks I will try to work with it. It selected view , but doenst created sketch and offset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Correct. It does not leave anything behind when it fails. That is due to the Transaction I am using within that rule. The Transaction bundles all of those little actions into one item in the UNDO list. If that were not there, you would see potentially a ton of lines of stuff that happened in your UNDO list due to what the code tried to do, and it would take a lot of clicking the UNDO button to undo all of it. The way it is right now, if it fails to create the offset geometry, it will abort that transaction, which undoes all those little actions it has done so far. If you want it to leave the sketch and projected geometry behind when it fails, just comment out (or remove) the "oTrans.Abort" line of code within the Catch side of the Try...Catch block.
Wesley Crihfield
(Not an Autodesk Employee)