Autodesk Inventor Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Solved! Go to Solution.
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Applications Engineer
Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.SculptFeatu
Dim mySurfaces As ObjectCollection
Set mySurfaces = ThisApplication.TransientObjects.CreateObjectColle
Dim mySculptPipe As SculptSurface
Dim mySculptBlock As SculptSurface
Set mySculptPipe = ofilePipe.ComponentDefinition.Features.SculptFeatu
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.SculptFeatu
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
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Dan,
Where is myPipe defined?
Can you post all of the code?
Applications Engineer
Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sure, full code below:...
Sub for_furtherwork()
Dim myPipe As ComponentOccurrence
Dim myBlock As ComponentOccurrence
Set myPipe = ThisApplication.ActiveDocument.ComponentDefinition
Set myBlock = ThisApplication.ActiveDocument.ComponentDefinition
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.CreateObjectColle
Dim mySculptPipe As SculptSurface
Dim mySculptBlock As SculptSurface
Set mySculptPipe = ofilePipe.ComponentDefinition.Features.SculptFeatu
'Set mySculptBlock = ofilePipe.ComponentDefinition.Features.SculptFeatu
Call mySurfaces.Add(mySculptPipe)
Call mySurfaces.Add(mySculptBlock)
Debug.Print "all surfaces added to transient object collection."
Call ofilePipe.ComponentDefinition.Features.SculptFeatu
Debug.Print "sculpt operation performed."
End Sub
Re: VBA or VB for sculpting overlappin g objects in an Assembly??
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.CreateD
' 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.CreateObjectColle
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.AddByDe
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
