Friday, October 4, 2019

PROPERTIES TO PARAMETERS (P2P) and some VBA!

Did not quite make the weekly update as discussed in the last posting, but two weeks is still better than three years.

In the past we had pushed properties into a parameter so the parameter could be used in a sketch to create a feature, but due my faulty memory, I could not recall how it was accomplished previously. 

So some research was undertaken and some iLogic was created.

This post at cadline community was used to develop the iLogic code.

Sub Main()

 Dim oDoc As Inventor.PartDocument 

 If ThisDoc.Document.DocumentType <> kPartDocumentObject Then
  Exit Sub
 Else
  oDoc = ThisDoc.Document
 End If

 Dim customPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
 Dim CustomPropName As String = "Catalog Number"
 Dim CustomPropValue As String 
 Dim DefaultCustomPropValue As String = "NOT FOUND!"

 Dim oParams As Parameters
 oParams=oDoc.ComponentDefinition.Parameters

 Dim oUserParams As UserParameters
 oUserParams=oParams.UserParameters

 Dim UParamName As String = "CATALOG_NUMBER"

 ' Look for the desired custom user property
 Try 
  CustomPropValue = customPropSet.Item(CustomPropName).Value
 Catch
  CustomPropValue = DefaultCustomPropValue
 End Try

 ' Look for the desired user parameter
 Try
  oUserParams(UParamName).Value = CustomPropValue 
 Catch
  ' assume error means not found and create it
  oUserParams.AddByValue(UParamName , CustomPropValue, "text")
 End Try

End Sub

Code formatting courtesy of http://hilite.me/


HPS bronze stud connector showing the catalog number, which is a custom iProperty.

Below is a screen snippet after editing the catalog number.


Per the rules for keeping the model as simple as possible, most of the fillets have been suppressed in the model file, simply by moving the End of Part up the tree.


We also were looking for an approach to document named work features which need to match a standard name in order to provide automation for an Inventor add-in (www.substationdesignsuite.com).

We did some test code using VBA, and were able to tag (with a leader) the named user points in the drawing, but if the work point name was revised, then the leader would need to be created again.


Option Explicit

Sub Main()

Dim oLdrPoints As ObjectCollection
Set oLdrPoints = ThisApplication.TransientObjects.CreateObjectCollection

' Get view from user
Dim drawDoc As Document
Set drawDoc = ThisApplication.ActiveDocument

If Not (TypeOf drawDoc Is DrawingDocument) Then
    Exit Sub
End If

Dim oSheet As Sheet
Set oSheet = drawDoc.ActiveSheet

' Select a workpoint to be labeled
Dim oSelect As New clsSelect

MsgBox "Select workpoint to be labeled."

Dim oDwgCenterPoint As Object
Set oDwgCenterPoint = oSelect.Pick(kDrawingCentermarkFilter) ' (kDrawingCurveSegmentFilter)

Dim LeaderStartPoint As point2D
Set LeaderStartPoint = oDwgCenterPoint.Position

Dim endPoint As point2D
Dim GetPoint As New clsGetPoint
Set endPoint = GetPoint.GetDrawingPoint("Click the desired location for the tag.", kLeftMouseButton)

' Add points to the point collection
oLdrPoints.Add endPoint     ' Point for location of sketch symbol
oLdrPoints.Add LeaderStartPoint   ' Point for location of leader arrow

'' Sub PlaceLeader(oWP As Variant, oSheet As Sheet, oLeaderPoints As ObjectCollection)
Call PlaceLeader(oDwgCenterPoint, oSheet, oLdrPoints)

' To Do:
'   9/26/19
'   Add the ability to add in a colleciton
'   of points
'   At the end we need to...
'   Convert to dot.net

' Cleanup Time!
Cleanup:
    Set oSelect = Nothing
    Set oLdrPoints = Nothing
    Set drawDoc = Nothing
    Set oSheet = Nothing

End Sub



Sub PlaceLeader(oWP As Variant, oSheet As Sheet, oLeaderPoints As ObjectCollection)

''PURPOSE : PLACE A LEADER ON THE SHEET WITH THE NAME OF THE WORKFEATURE

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oPoint2D As point2D
Set oPoint2D = oWP.Position

Dim oWorkPoint As WorkPoint
Set oWorkPoint = oWP.AttachedEntity


' Create an intent and add to the ObjectCollection
Dim oGeoIntent As GeometryIntent
Set oGeoIntent = oSheet.CreateGeometryIntent(oWorkPoint)

Call oLeaderPoints.Add(oPoint2D)

Dim LdrText As String
LdrText = oWP.ModelWorkFeature.Name

Dim oLdrNote As LeaderNote
Set oLdrNote = oSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, LdrText)

Dim oFirstNode As LeaderNode
Set oFirstNode = oLdrNote.Leader.RootNode.ChildNodes.Item(1)

Dim oSecondNode As LeaderNode
Set oSecondNode = oFirstNode.ChildNodes.Item(1)

Call oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oLeaderPoints.Item(2).X, oLeaderPoints.Item(2).Y))

'Stop

End Sub

Part file with named point.


Drawing with leader text extracted from point name.

Next on the list is to convert the VBA code into VB.net code so we can complete the addin.  Most likely will utilize an attribute to link the drawing leader to the actual point so that the value can be updated if the model is revised.

Tune in next time for our notes on creating your own custom content center conduit fittings!









Sunday, September 22, 2019

Progress over the years and a blog reboot!

September 2019: BLOG REBOOT!

Some background history, we began learning Inventor and Vault while trying to to use Inventor to model substation in 2014.  Was a hard row to hoe, due to lack of experience with both Inventor and electrical substations.

Circa 2014

First example was from 2014, We were only working on the high bay portion of the substation. The client was doing everything on the other side of the transformer.  See the window below for a "shared" model which was posted on the BIM360 cloud.
   

Circa 2017

Skip ahead a few years to 2017 and we were able to utilize Inventor and the Substation Design Suite for another substation project for a different client.  Again only working on the high bay portion of the substation.











Circa 2019

We had some modeling resources available in 2019 and were able to model up the low bay side of the client from 2014.  Working on a different substations.  Mostly all above ground, but have begun to utilize the below ground tools available with the Substation Design Suite.






Conduit Modeling...

We have begun to incorporate the conduit portion, at least attempting to document the underground portion for the client in parallel with the 2D drawing creation.




Substation Steel Structures...

We also created a new 25kV circuit breaker bypass stand for this client.  Modeling and detailing drawings were all created with Inventor.


Assembly Drawing


Fabrication Drawing

Custom iLogic and VBA code is utilized to extract the gross material weight and to properly match the company drawing format.

Next weeks post...

The next post will cover pushing custom iProperties into a user parameter and then using the value in a user parameter to show the value with a part feature. It does not seem possible to push an iProperty value into a sketch in a part, but you can push a parameter into a part sketch.

.

Trying to document what we've learned so that it will not be forgotten by those who follow.