SW API to change layer

Discussion in 'SolidWorks' started by pandrew, Oct 15, 2008.

  1. pandrew

    pandrew Guest

    Hi

    Need help with API that changes the layer of a selected entity in a
    drawing document.
    Any ideas?

    Thanks
     
    pandrew, Oct 15, 2008
    #1
  2. pandrew

    TOP Guest

    Have you tried recording a macro?

    TOP
     
    TOP, Oct 15, 2008
    #2
  3. pandrew

    pandrew Guest

    Have you tried recording a macro?
    Yes, but it doesn't record the actions when I change layer.
     
    pandrew, Oct 15, 2008
    #3
  4. pandrew

    That70sTick Guest

    Layer is set as a property of an object in a drawing. Get the
    selected object using the Selection Manager, then change the object's
    property. You probably can get away with using a generic "Object"
    variable for the entities whose layer you wish to change, as long as
    that entity has a Layer property associated with it.

    If you do not know how to use the Selection Manager, it's time to
    learn. Macro recording won't help much there.
     
    That70sTick, Oct 15, 2008
    #4
  5. pandrew

    pandrew Guest

    Thanks, now I got it to work!
     
    pandrew, Oct 16, 2008
    #5
  6. pandrew

    pandrew Guest

    Hmm, it doesn't seem to work the same way when the selected entity is
    a dimension.
    Any ideas about this?
     
    pandrew, Oct 16, 2008
    #6
  7. pandrew

    That70sTick Guest

    Hmm, it doesn't seem to work the same way when the selected entity is
    Dimensions can be tricky. When you select a dimension, the selected
    object type is usually a "DisplayDimension". From this object, you
    need to access the "Annotation" object using
    "DisplayDimension::GetAnnotation".

    Example code below takes a generic object and sets "Anno" to the
    Annotation object if it is a DisplayDimension. After that, you can
    set SelectedObject = Anno or just use Anno.Layer to change layer.

    Dim SelectedObject as Object
    Dim DispDim as SldWorks.DisplayDimension
    Dim Anno as SldWorks.Annotation
    Set DispDim=SelectedObject
    If Not DispDim is Nothing Then Set Anno = SelectedObject.GetAnnotation
     
    That70sTick, Oct 16, 2008
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.