Hi Ed;
Thanks for your reply and as you say the internet is silent on this one.
I got my initial code from this post on AUGI
https://forums.augi.com/showthread.php?72798-Sectioning-Solids
and developed it and tried to figure it out further. But there are still many parts that I don't understand.
I had some development getting layers correct and which lines should be shown to some extent.
Here is the code. It is the end part that generates the error.
Line 148:
"setSectionTypeSettings.GenerationOptions = acSectionGenerationDestinationNewBlock"
setSectionTypeSettings is actually "Dim setSectionTypeSettings As AcadSectionTypeSettings"
My solution right now is to collect all the generated objects and just create a block myself.
Code in Full:
Public Sub CreateSectionViewsFrom3DSolid()
Dim oAcadSec As AcadSection
Dim SectionSettings As AcadSectionSettings
Dim setSectionTypeSettings As AcadSectionTypeSettings
Dim dPlaneVector(0 To 2) As Double
Dim x3DSolid As Acad3DSolid
Dim vBasePt As Variant
Dim vPt1 As Variant
Dim vPt2 As Variant
' Get the solid
ThisDrawing.Utility.GetEntity x3DSolid, vBasePt, "Pick 3D Solid"
' get 2 section points
vPt1 = ThisDrawing.Utility.GetPoint(, "Pick first point")
vPt2 = ThisDrawing.Utility.GetPoint(, "Pick end point")
' The below vector [0,0,1] will give a vertical section through a solid
dPlaneVector(0) = 0: dPlaneVector(1) = 0: dPlaneVector(2) = 1
Err.Clear
On Error Resume Next
'------------------------------------------------------------------------------
' Insert Section object
'------------------------------------------------------------------------------
' Create the section object
Set oAcadSec = ThisDrawing.ModelSpace.AddSection(vPt1, vPt2, dPlaneVector)
With oAcadSec
.Elevation = 350
.State = acSectionStatePlane
.State2 = acSectionState2Slice
.SliceDepth = 250#
Set SectionSettings = .Settings
.Update
End With
With SectionSettings
.CurrentSectionType = acSectionType2dSection
End With
Set setSectionTypeSettings = SectionSettings.GetSectionTypeSettings(acSectionType2dSection)
'------------------------------------------------------------------------------
' Section object settings
'------------------------------------------------------------------------------
' Section Settings Background lines
With setSectionTypeSettings
.BackgroundLinesVisible = False
.BackgroundLinesHiddenLine = False
.BackgroundLinesLayer = "PC Bea. Thn"
.BackgroundLinesLinetype = "ByLayer"
'.BackgroundLinesColor=""
'.BackgroundLinesLinetypeScale=5
'.BackgroundLinesLineweight=0.18
'.BackgroundLinesPlotStyleName="UPH Monochrome.ctb"
End With
' Section Settings InterSection boundary
' The outline of the Intersection Boundary
With setSectionTypeSettings
.IntersectionBoundaryVisible = True
.IntersectionBoundaryLayer = "PC Pnl. Thn"
.IntersectionBoundaryLinetype = "ByLayer"
'.IntersectionBoundaryColor=""
'.IntersectionBoundaryDivisionLines = False
'.IntersectionBoundaryLinetypeScale = 5
'.IntersectionBoundaryLineweight = 0.18
'.IntersectionBoundaryPlotStyleName = "UPH Monochrome.ctb"
End With
' Section Settings Intersection fill
' For a face when a section goes through the object
With setSectionTypeSettings
.IntersectionFillVisible = False
'.IntersectionFillColor = "red"
'.IntersectionFillFaceTransparency = [long] [Live Section Only]
'.IntersectionFillHatchAngle=45 [units radian??]
'.IntersectionFillHatchPatternName = "ANSI31"
'.IntersectionFillHatchPatternType = acHatchPatternTypePreDefined
'.IntersectionFillHatchScale = 5
'.IntersectionFillHatchSpacing = 150#
'.IntersectionFillLayer = "PC Htc"
'.IntersectionFillLinetype = "Continous"
'.IntersectionFillLinetypeScale = 5
'.IntersectionFillLineweight = 0.18
'.IntersectionFillPlotStyleName = "UPH Monochrome.ctb"
End With
' Section Settings ForeGround Lines
' This is cut away geometry
With setSectionTypeSettings
.ForegroundLinesVisible = False
.ForegroundLinesHiddenLine = False
'.ForegroundLinesColor=""
'.ForegroundLinesEdgeTransparency = [long] [Live Section Only]
'.ForegroundLinesFaceTransparency= [long] [Live Section Only]
'.ForegroundLinesLayer = "PC Pnl .Thn"
'.ForegroundLinesLinetype = "Continous"
'.ForegroundLinesLinetypeScale = 5
'.ForegroundLinesLineweight = 0.18
'.ForegroundLinesPlotStyleName = "UPH Monochrome.ctb"
End With
' Section Settings CurveTangency Lines
With setSectionTypeSettings
.CurveTangencyLinesVisible = False
'.CurveTangencyLinesColor=""
'.CurveTangencyLinesLayer="PC Pnl
'.CurveTangencyLinesLinetype="Continous"
'.CurveTangencyLinesLinetypeScale=5
'.CurveTangencyLinesLineweight = 0.18
'.CurveTangencyLinesPlotStyleName="UPH Monochrome.ctb"
End With
' Section Settings Others
With setSectionTypeSettings
'.GenerationOptions = acSectionGenerationDestinationNewBlock
'.DestinationBlock = "TestBlock"
'.DestinationFile = "C:\temp\file.dwg"
'.GenerationOptions = acSectionGenerationDestinationFile
'.GenerationOptions = acSectionGenerationDestinationReplaceBlock
'.GenerationOptions = acSectionGenerationSourceAllObjects
'.GenerationOptions = acSectionGenerationSourceSelectedObjects
'.SourceObjects = vObjects
End With
oAcadSec.Update
Dim vBoundaryObjs As Variant
Dim vFillObjs As Variant
Dim vBackGroundObjs As Variant
Dim vForeGroundObjs As Variant
Dim vCurveTangencyObjs As Variant
Err.Clear
setSectionTypeSettings.GenerationOptions = acSectionGenerationDestinationNewBlock
Debug.Print "1: " & Err.Description
Err.Clear
vBlockGen = setSectionTypeSettings.DestinationBlock
Debug.Print "2: " & Err.Description
oAcadSec.GenerateSectionGeometry x3DSolid, vBoundaryObjs, vFillObjs, vBackGroundObjs, vForeGroundObjs, vCurveTangencyObjs
oAcadSec.Delete
End Sub