dogarila
Mechanical
- Oct 28, 2001
- 594
I'm trying to write a simple application:
In a DRW file:
1.User selects a circle in a view.
2.The program draws a line from centre to upper side of circle, another line from centre to right side of circle and an arc from end of line1 to end of line2 with the same rad as the circle.
3. In the resulting area insert an area hatch.
The code I wrote so far is:
'Option Explicit
Public swApp As Object
Public Part As Object
Public SelMgr As Object
Public SelObj As Object
Public Crv As Object
Dim Line1 As Object, Line2 As Object, Arc1 As Object
Dim CrvParam As Variant
Dim dblRadius As Double, dblX As Double, dblY As Double, dblZ As Double
Private Sub Main()
Set swApp = CreateObject("SldWorks.Application"
Set Part = swApp.ActiveDoc
' Get the selected item from the SW selection mgr
Set SelMgr = Part.SelectionManager()
If SelMgr.GetSelectedObjectCount > 0 Then
' Ensure the 1st selected item is an edge
If SelMgr.GetSelectedObjectType(1) = swSelEDGES Then
' The user has an edge selected
Set SelObj = SelMgr.GetSelectedObject2(1)
Set Crv = SelObj.getcurve
End If
End If
If Not Crv.iscircle Then
swApp.SendMsgToUser ("You need to preselect a hole"
Set swApp = Nothing
Set Part = Nothing
Set SelMgr = Nothing
Set SelObj = Nothing
End
End If
CrvParam = Crv.CircleParams 'returns parameters of circle
dblRadius = CrvParam(6)
dblX = CrvParam(0)
dblY = CrvParam(1)
dblZ = CrvParam(2)
Set Line1 = Part.CreateLine2(dblX + dblRadius, dblY, dblZ, dblX, dblY, dblZ)
Set Line2 = Part.CreateLine2(dblX, dblY, dblZ, dblX, dblY + dblRadius, dblZ)
Set Arc1 = Part.CreateArc2(dblX, dblY, dblZ, dblX + dblRadius, dblY, dblZ, dblX, dblY + dblRadius, dblZ, 1)
junk = Line1.Select(False)
junk = Line2.Select(True)
junk = Arc1.Select(True)
Part.InsertHatchedFace
End Sub
What I get is 2 lines, an arc and the area hatched but the location is the location of the specified circle in the solid part, not on the view in the drawing. How do I get the position of the circle in the drawing view?
Andrew(Netshop21)
In a DRW file:
1.User selects a circle in a view.
2.The program draws a line from centre to upper side of circle, another line from centre to right side of circle and an arc from end of line1 to end of line2 with the same rad as the circle.
3. In the resulting area insert an area hatch.
The code I wrote so far is:
'Option Explicit
Public swApp As Object
Public Part As Object
Public SelMgr As Object
Public SelObj As Object
Public Crv As Object
Dim Line1 As Object, Line2 As Object, Arc1 As Object
Dim CrvParam As Variant
Dim dblRadius As Double, dblX As Double, dblY As Double, dblZ As Double
Private Sub Main()
Set swApp = CreateObject("SldWorks.Application"
Set Part = swApp.ActiveDoc
' Get the selected item from the SW selection mgr
Set SelMgr = Part.SelectionManager()
If SelMgr.GetSelectedObjectCount > 0 Then
' Ensure the 1st selected item is an edge
If SelMgr.GetSelectedObjectType(1) = swSelEDGES Then
' The user has an edge selected
Set SelObj = SelMgr.GetSelectedObject2(1)
Set Crv = SelObj.getcurve
End If
End If
If Not Crv.iscircle Then
swApp.SendMsgToUser ("You need to preselect a hole"
Set swApp = Nothing
Set Part = Nothing
Set SelMgr = Nothing
Set SelObj = Nothing
End
End If
CrvParam = Crv.CircleParams 'returns parameters of circle
dblRadius = CrvParam(6)
dblX = CrvParam(0)
dblY = CrvParam(1)
dblZ = CrvParam(2)
Set Line1 = Part.CreateLine2(dblX + dblRadius, dblY, dblZ, dblX, dblY, dblZ)
Set Line2 = Part.CreateLine2(dblX, dblY, dblZ, dblX, dblY + dblRadius, dblZ)
Set Arc1 = Part.CreateArc2(dblX, dblY, dblZ, dblX + dblRadius, dblY, dblZ, dblX, dblY + dblRadius, dblZ, 1)
junk = Line1.Select(False)
junk = Line2.Select(True)
junk = Arc1.Select(True)
Part.InsertHatchedFace
End Sub
What I get is 2 lines, an arc and the area hatched but the location is the location of the specified circle in the solid part, not on the view in the drawing. How do I get the position of the circle in the drawing view?
Andrew(Netshop21)