Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with circle parameters

Status
Not open for further replies.

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)
 
Replies continue below

Recommended for you

You are grabbing the wrong circle parameters. You need to use the axis values instead of the center values.
Code:
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.
 
I tried to use axis values and I get my sketch drawn in the center of the view, not in the center of the circle. It's an improvement but not exactly what I am looking for.

Andrew (Netshop21)
 
I am not sure why this is happening but it seems as though it works when completely zoomed out. If I zoom in to the entitiy and run the program, the new entities are not drawn in the proper location. Also, if I put a ZoomToFit command in, it does not work either.

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.
 
Strange!
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
 
I just found the problem. If you use the origin values as you had them, they will be placed with reference to the drawing sheet origin. You will need to add the offset of the drawing view (View.Position). You should be able to see this by dragging the drawing view to the sheet's origin. They should line up. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
I am trying to get the X and Y coordinates of the view using:

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

 
How do I get the name of the view in API (VB) when I have an edge of a circle selected in that particular view?

Netshop21
 
netshop21:

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.
 
Congrats dsi on your bundle of joy!!

Cya in Jan! Scott Baugh, CSWP :)
George Koch Sons,LLC
Evansville, IN 47714
sjb@kochllc.com
 
Thanks! It sure makes for a wonderful holiday. :) DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor