help with circle parameters
help with circle parameters
(OP)
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)






RE: help with circle parameters
dblX = CrvParam(3)
dblY = CrvParam(4)
dblZ = CrvParam(5)
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: help with circle parameters
Andrew (Netshop21)
RE: help with circle parameters
Another thing to note is that you should add Part.EditSketch before you process the CreateLine commands.
Without spending a ton of time on this, I am not quite sure what to do.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: help with circle parameters
Is it possible to mate the arc of the new sketch concentric with the selected circle as the next step in the program? That will move the sketch to the required location.
I tried to add these lines after creating the sketch but it doesn't work:
junk = Crv.Select(False)
junk = Arc1.Select(True)
Part.SketchAddConstraints "sgCONCENTRIC"
Andrew
RE: help with circle parameters
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: help with circle parameters
Public MyView as Object
Dim ViewPos as Variant
Dim dblXview as Double, dblYview as Double
Set MyView = Part.ActiveView
ViewPos = MyView.Position
dblXview = ViewPos(0)
dblYview = ViewPos(1)
I get "Object doesn't support this property or method" error
in line: ViewPos = MyView.Position
????
Netshop21
RE: help with circle parameters
Netshop21
RE: help with circle parameters
Sorry for not responding faster. My wife and I just had our first child Monday morning. I am taking the rest of the year off and I don't have access to my other computer. I will have to look into this once I return.
Until then...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: help with circle parameters
Cya in Jan!
Scott Baugh, CSWP
George Koch Sons,LLC
Evansville, IN 47714
sjb@kochllc.com
RE: help with circle parameters
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.