Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA or VB for sculpting overlapping objects in an Assembly??

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
mitcham_boy
1587 Views, 6 Replies

VBA or VB for sculpting overlapping objects in an Assembly??

Hi

 

I have an assembly with various parts in it.  I am trying to write a routine that will

1) systematically traverse the assembly and find parts that overlap,

2) where they overlap perform a sculpt operation on the parts

 

Whilst i can do this manually by edit>copy object>sculpt>select surface ...  i don't know how to mimic this programmatically. 

 

 So far i have coded to do it in a very hamfisted way by making a derived part file from the overlapping parts, opening the derived part file and performing the sculpt, replacing the original part in the assembly with its new derived-sculpted part and then continuing to traverse the assembly tree..  - it is super slow and uses lots of file operations.

 

Does anyone have any examples of a slick way to do this??

 

Thanks in advance

regards

Dan

6 REPLIES 6
Message 2 of 7
jdkriek
in reply to: mitcham_boy

The derive-sculpt method that you described is the only way I'm aware of.

 

For a better solution I'm afraid we need more exposed to the API.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 7
mitcham_boy
in reply to: jdkriek

Jonathan

 

Thank you for your very quick reply.

I am gleaning most of what i can from the VBA f1 help, these forums and some very useful presentations by Brian Ekin on the AutoDesk website - is there a recommended book on programming the API that walks through all the geometric/file based/etc operations with examples?

 

thanks again

Dan.

Message 4 of 7
mitcham_boy
in reply to: mitcham_boy

Hi Jonathan

 

I had been hoping to use the SculptFeatures method on a transient surface collection object instead of the derive-sculpt but i can't quite get the hang of the surface objects, can you see what i am doing wrong? :

 

For example: i have an assembly containing a pipe and a small block that overlaps the pipe.  I want to remove the small block from the pipe wall. 

ofilePipe is the part document for the pipe. 

ofileBlock is the part document for the block

 

So i want to use the following 'SculptFeatures' method passing it a surfaces collection which is the surface bodies of both the pipe and block... Call ofilePipe.ComponentDefinition.Features.SculptFeatures.Add(mySurfaces, False) where true adds material, false removes material.  So to use the above i create a transient object collection named mySurfaces containing the surface bodies from each part...  But it falls over at the line which is bold italic because there's something wrong with my attempt to obtain the surfaces of a part.

 

   Dim mySurfaces As ObjectCollection
   Set mySurfaces = ThisApplication.TransientObjects.CreateObjectCollection
   Dim mySculptPipe As SculptSurface
   Dim mySculptBlock As SculptSurface

   Set mySculptPipe = ofilePipe.ComponentDefinition.Features.SculptFeatures.CreateSculptSurface(myPipe.SurfaceBodies.Item(1))  'get the pipe part's surfaces as a surface object
   Set mySculptBlock = 'ditto but for the block part

   Call mySurfaces.Add(mySculptPipe) ' add the pipe surface object to the collection
   Call mySurfaces.Add(mySculptBlock) 'add the block surface object to the collection
   Debug.Print "all surfaces added to transient object collection."

   Call ofilePipe.ComponentDefinition.Features.SculptFeatures.Add(mySurfaces, False) 'true adds material, false removes material

   Debug.Print "sculpt operation performed to original part document without requirement for derived part files."

 

 

Can you advise what i'm doing wrong?

thanks and regards

Dan

Message 5 of 7
jdkriek
in reply to: mitcham_boy

Hi Dan,

 

Where is myPipe defined?

 

Can you post all of the code?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 6 of 7
mitcham_boy
in reply to: jdkriek

Sure, full code below:...

 

Sub for_furtherwork()

  Dim myPipe As ComponentOccurrence
  Dim myBlock As ComponentOccurrence
  Set myPipe = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(1)
  Set myBlock = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(2)

 

Debug.Print myPipe.Name
Debug.Print myBlock.Name

 

  Dim ofilePipe As PartDocument
  Set ofilePipe = myPipe.Definition.Document
  Dim mySurfaces As ObjectCollection
  Set mySurfaces = ThisApplication.TransientObjects.CreateObjectCollection
  Dim mySculptPipe As SculptSurface
  Dim mySculptBlock As SculptSurface

  Set mySculptPipe = ofilePipe.ComponentDefinition.Features.SculptFeatures.CreateSculptSurface(myPipe.SurfaceBodies.Item(1))
  'Set mySculptBlock = ofilePipe.ComponentDefinition.Features.SculptFeatures.CreateSculptSurface(myBlock)
  Call mySurfaces.Add(mySculptPipe)
  Call mySurfaces.Add(mySculptBlock)

Debug.Print "all surfaces added to transient object collection."

 

  Call ofilePipe.ComponentDefinition.Features.SculptFeatures.Add(mySurfaces, False) 'False removes material

 

Debug.Print "sculpt operation performed."

 

End Sub

Message 7 of 7
mitcham_boy
in reply to: mitcham_boy

I have found the following solution courtesy of Brian Eakin's "API 2011 What's New" .ivb example modules

Clearly it is only valid for 2011 onwards.

 

' The following sample demonstrates associatively copying bodies across parts
' in an assembly.  Before running this sample open the sample assembly called
' CutExample.iam.  It can be run on any assembly that contains two parts, but
' the sample demonstrates a common use of the functionality.  The use in this
' case is to use one part to cut another one, where the positions of the parts
' are the defined in the assembly but the cut is performed within the part and
' not as an assembly feature.
Sub AssociativeBodyCopy()
    ' Open the existing sample assembly.
    Dim assemblyDoc As AssemblyDocument
    Set assemblyDoc = ThisApplication.ActiveDocument

    Dim assemblyDef As AssemblyComponentDefinition
    Set assemblyDef = assemblyDoc.ComponentDefinition

    ' Get the first occurrence, which will be treated as the base part.
    Dim baseOcc As ComponentOccurrence
    Set baseOcc = assemblyDef.Occurrences.Item(1)

    ' Get the second occurrence, which will be used as the cut tool.
    Dim toolOcc As ComponentOccurrence
    Set toolOcc = assemblyDef.Occurrences.Item(2)

    ' Get the component definition of the base part.
    Dim baseDef As PartComponentDefinition
    Set baseDef = baseOcc.Definition

    '** Create an associative surface base feature in the second part.
   
    ' Create a definition object in the context of the first part.
    Dim baseFeatureDef As NonParametricBaseFeatureDefinition
    Set baseFeatureDef = baseDef.Features.NonParametricBaseFeatures.CreateDefinition

    ' Add the body of the second part to the list of items to be copied.  Since this
    ' is getting the body from the occurrence it is actually a SurfaceBodyProxy
    ' object in the context of the assembly.
    Dim bodyColl As ObjectCollection
    Set bodyColl = ThisApplication.TransientObjects.CreateObjectCollection
    bodyColl.Add toolOcc.SurfaceBodies.Item(1)

    ' Set up the definition object.  When setting the IsAssociative flag to True, the
    ' Output type must be either a Surface or Composite.  A solid is not valid in that case.
    baseFeatureDef.BRepEntities = bodyColl
    baseFeatureDef.OutputType = kSurfaceOutputType
    baseFeatureDef.TargetOccurrence = baseOcc
    baseFeatureDef.IsAssociative = True

    ' Create the associative copy.
    Dim baseFeature As NonParametricBaseFeature
    Set baseFeature = baseDef.Features.NonParametricBaseFeatures.AddByDefinition(baseFeatureDef)

    assemblyDoc.Update
   
    ' Get the WorkSurface that was created as a result of the import.
    Dim surface As WorkSurface
    Set surface = baseFeature.SurfaceBody.Parent
   
    ' Split the base part using the new surface.
    Call baseDef.Features.SplitFeatures.TrimSolid(surface, baseDef.SurfaceBodies.Item(1), False)
   
    ' Turn off the visibilty of the work surface.
    surface.Visible = False
   
    ThisApplication.ActiveView.Update
End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report