×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

help with circle parameters

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)

RE: help with circle parameters

You are grabbing the wrong circle parameters. You need to use the axis values instead of the center values.

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

(OP)
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)

RE: help with circle parameters

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.

RE: help with circle parameters

(OP)
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

RE: help with circle parameters

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.

RE: help with circle parameters

(OP)
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

RE: help with circle parameters

(OP)
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

RE: help with circle parameters

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.

RE: help with circle parameters

Congrats dsi on your bundle of joy!!

Cya in Jan!

Scott Baugh, CSWP
George Koch Sons,LLC
Evansville, IN 47714
sjb@kochllc.com

RE: help with circle parameters

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources