iLogic Rule - Drawing - Get selected view scale into custom property

iLogic Rule - Drawing - Get selected view scale into custom property

Anonymous
Not applicable
3,264 Views
14 Replies
Message 1 of 15

iLogic Rule - Drawing - Get selected view scale into custom property

Anonymous
Not applicable

Hi !

 

One of our clients have specific drawing standards and on some projects, we have to place multiple items on one single sheet. We use a sketch symbol to identify the specified detailed item number (<ITEMNUM>) and general display scale (<VIEWSCALE>), see attached png below.

 

What I would like to do is upon inserting the symbol, having a prompt asking me to select a view (or selecting a view before inserting the sketch), and assing the view scale value to the <VIEWSCALE> property. By changing the item general view scale, the scale value would change automatically in the sketch symbol. I think the challenge is that each sketch symbol is «linked» to different views, with different scales.

 

Right now we're exporting the drawing in dwg and insert / specify manually the Item Blocks and scale and it really is time consuming.

 

Is this something doable? I'm new to creating iLogic Rules and I would like to better understand how it works.

 

Thanks!

0 Likes
3,265 Views
14 Replies
Replies (14)
Message 2 of 15

PaulMunford
Autodesk
Autodesk
This post:
http://www.mcadforums.com/forums/viewtopic.php?f=5&t=12441

Hints that you can attach a sketched symbol to an Inventor view to pick up the properties from the view.

If you try it out can you let us know if it works?


Paul Munford
Technical Onboarding Architect
Linkedin 

0 Likes
Message 3 of 15

Anonymous
Not applicable

Hi,

 

Thanks for your reply! I tried it and it works...but specifically for the initial view scale, the property name is <Initial View Scale>. As you guessed it, it works only with the first base view scale. So on a one-item-one-sheet standard it's fine, but on a multiple items per sheet, it doesn't work. I was hoping to extend the solution to section views et detail views too by using the same method but it didn't work 😕

 

Thank for your help though, I appreciate it.

 

 

Message 4 of 15

PaulMunford
Autodesk
Autodesk

It's a great idea.

 

I checked the Inventor Ideastation, and it's already been suggested. You might want to visit this post and lend your Kudos?

http://forums.autodesk.com/t5/inventor-ideas/customised-view-labels/idi-p/4301201

 

Paul



Paul Munford
Technical Onboarding Architect
Linkedin 

0 Likes
Message 5 of 15

HermJan.Otterman
Advisor
Advisor

why can't you just use the label from each view, it wil give you the scale, and will update if you change it.

 

here is a screencast: http://autode.sk/2eLnyEi

 

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 6 of 15

Anonymous
Not applicable

Because like I said, the default view labels are not as per my client standards.See my previous posts to an example of it's standard view label block.

Message 7 of 15

Anonymous
Not applicable

Thanks for the link, but it's been asked 3 years ago, I don't think it will be implemented soon. I found a way inserting the selected view properties into prompted entries of the block, but since they are prompted entries, the view scale for example doesn't update automatically. It's kind of an incomplete solution for now.

Message 8 of 15

PaulMunford
Autodesk
Autodesk

The only other workaround I can think of is to use the standard view labels, but then carefully overlay your sketched symbol.

 

Another incomplete solution, because the scale will now update, but the position of the sketched symbol wont 😞



Paul Munford
Technical Onboarding Architect
Linkedin 

0 Likes
Message 9 of 15

HermJan.Otterman
Advisor
Advisor

Hello Aardvark101,

 

I'm just wondering where does the itemnumber come from?

if you place multiple parts on one drawing, the item number starts every time at 1.

 

 

(so a balloon is attached to an edge = part... . )

but now you want to do this with a sketched symbol...to get the item, itemnumber, viewscale

I gues you could find the part, and the view,

the next thing is; updating it when it changes...best option would be to write an addin

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 10 of 15

Anonymous
Not applicable

I made an iLogic rule to be used only in the top assembly, that checks the BOM number of each part, and assign the number to a custom variable <ITEMNUMBER> for each individual part (or welded asm). The sketched symbol automatically finds the appropriate number of the selected view. But I have to manually hide the symbol's leader, if you delete the leader, you lose the "link" and <ITEMNUMBER> shows the value of the first created view.

0 Likes
Message 11 of 15

HermJan.Otterman
Advisor
Advisor

OK, I did some coding,

 

it could be better, but it works of PARTS.

 

what version of inventor are u using?

let me know, then I can send you a part with a sketchsymbol.

 

You can create a new part , and create a sketched symbol with the name Numbers.

(If you want a different name, then also change it in the code.)

the sketched symbol has to have 2 prompted entries (if you want more, then you need to add the text also to the prompstrings! , they all have to be filled)

 

then create views of part, and use the tool.,

pick an edge, and the sketched symbol will be placed.

 

You'll need to do some coding to make it better.

 

 

        ' Set a reference to the drawing document.
        ' This assumes a drawing document is active.
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.ActiveDocument

        ' Set a reference to the active sheet.
        Dim oActiveSheet As Sheet
        oActiveSheet = oDrawDoc.ActiveSheet

        Dim oDrawCurveSegment As Inventor.DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select an Edge")

        ' Set a reference to the drawing curve.
        Dim oDrawingCurve As DrawingCurve
        oDrawingCurve = oDrawCurveSegment.Parent

        Dim oDrawView As Inventor.DrawingView = oDrawingCurve.Parent
        Dim oViewScale As String = oDrawView.ScaleString
        Dim oPropSets As Inventor.PropertySets = oDrawingCurve.ModelGeometry.parent.parent.Document.propertysets
        Dim oPartNumber As String = oPropSets(3).Item("Part Number").Value


        ' Get the mid point of the selected curve
        ' assuming that the selection curve is linear
        Dim oMidPoint As Point2d
        oMidPoint = oDrawingCurve.MidPoint

        ' Set a reference to the TransientGeometry object.
        Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry

        Dim oLeaderPoints As ObjectCollection
        oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

        ' Create a few leader points.
        Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10))
        Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

        ' Create an intent and add to the leader points collection.
        ' This is the geometry that the symbol will attach to.
        Dim oGeometryIntent As GeometryIntent
        oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

        oLeaderPoints.Add(oGeometryIntent)

        ' Get the first symbol definition
        Dim oSketchSymDef As SketchedSymbolDefinition
        oSketchSymDef = oDrawDoc.SketchedSymbolDefinitions.Item("numbers")

        Dim sPromptStrings(1) As String
        sPromptStrings(0) = oViewScale
        sPromptStrings(1) = oPartNumber

        ' Create the symbol with a leader
        Dim oSketchedSymbol As SketchedSymbol
        oSketchedSymbol = oActiveSheet.SketchedSymbols.AddWithLeader(oSketchSymDef, oLeaderPoints, ,, sPromptStrings)



 

One thing that remains is the updating.....

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 12 of 15

HermJan.Otterman
Advisor
Advisor

what if you use the part in different assemblies?, then the custom property "Itemnumber" wants to have different values?

or if it is a standard part, which normaly is in a library and therefore readonly, yo can't add/change the property...

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 13 of 15

ahobby
Contributor
Contributor

 @HermJan.Otterman

 

Hi guys,

 

I stumbled on this thread while searching for a solution to this EXACT problem I'm working with right now. We are a company that has worked in autocad for years and are slowly working inventor into the mix. One of the big issues is that Inventors drawing labeling isn't that great looking.

 

I've piece together the attached code from snippets found online, and it works but theres one big bug. When you run the code, if you have anything typed into the prompted text field "DESCRIPTION" (i.e. "Front Elevation") it overwrites the existing text with the default.

 

 

My VB and ilogic skills are extremely rudimentary, so I'm really at a loss how to make this work.

 

Here's how the code runs right now:

 

an IF statement looks at the sketch symbols and if its called View_Label, it deletes it (grumble grumble...)

 

The code then goes through the drawing, places a new sketch symbol, pulls the scale from the view, and fills out the prompted text fields "NAME" and "SCALE".

 

 

Heres how I would like it to run... in theory:

 

-The first time the code is run, the view labels are placed and the text is pulled from the view .

 

-During drawing, I change some of the prompted entries (i.e. fill out description to read "Front Elevation")

 

-When the code is run again, it checks to see if there is text different from the default in the "description" field. IF there is, it doesn't delete the label AND does not place one there. If there isn't (i.e. I havent touched the label), it just runs normally

 

 

At one point I had successfully gotten the code to not delete the prompted text I put in but it also was putting that text in all the labels. I think my variable was declared public which was probably the source of the issue.... unfortunately during my screwing around the code I managed to delete the snippet that did that. Smiley Embarassed

 

SyntaxEditor Code Snippet

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oSymbol As SketchedSymbol
Dim oSymbols As SketchedSymbols

'iterate through all of the sheets
For Each oSheet In oSheets
    'remove existing sketched symbols named View Label 
    For Each oSymbol  In oSheet.SketchedSymbols
    If oSymbol.Definition.Name = "View_Label" Then
    oSymbol.Delete
    Else 
    End If
    Next
    
'set sheet active    
oSheet.Activate
'set a refernce to the drawing views collection
oViews = oDoc.ActiveSheet.DrawingViews
    ' Iterate through all of the views
    For Each oView In oViews
    'This places a sketched symbol with the name "View_Label"
    Dim oSymDef As SketchedSymbolDefinition
    'defind the sketch symbol to be inserted
    oSymDef = oDoc.SketchedSymbolDefinitions.Item("View_Label")
    
    'set a string array with values for the prompted entries found in the symbol
 
    Dim sPromptStrings(2) As String 
     sPromptStrings(0) = "" & oView.ScaleString 'set to view scale
    sPromptStrings(1) = oView.Name 'set to view name
    sPromptStrings(2) = "DESCRIPTION"
    
    'set the position for the sketched symbol to be inserted 
    ' and spaced off of the selected view center
    Dim oPosition As Point2d: oPosition = oView.Center
    oPosition.y = oPosition.y - (oView.Height / 2 + 2)
    'insert the sketched symbol and set the prompted entries
    oSymbol = oSheet.SketchedSymbols.Add(oSymDef, oPosition,0,1,sPromptStrings)
    Next    
Next

'activate sheet1
oDoc.Sheets.Item(1).Activate

 

 

0 Likes
Message 14 of 15

Anonymous
Not applicable

Hello everyone!

 

I know this post is relatively old, but still actual and incomplete/unresolved …

 

At the time of creating the post , with unsuccessfull results, I made an arrangement with my client to deliver drawings that are not exactly like his drawing standard. (Mainly telling him that a lot of people in this world are paid to maintain the ASME Y.14.5 standard, and that there is no point in reinventing the wheel by creating another "in-house" standard… But this is another subject).

 

Clients… being what they are, put this matter on the table again… So, mainly because I like challenges and to learn something new, i'll give it a shot again with everything that has been discussed here. I'm pretty sure it's doable with a good iLogic script.

 

I'll combine all the ideas that have been posted yet, and will do a follow-up with you guys.

 

Have a good one!

0 Likes
Message 15 of 15

Anonymous
Not applicable

Hi guys!

 

Little update on this matter.

 

I found a nice iLogic rule to be created in an assembly, that looks at the BOM table (Structured), and store the Item Number in an iProperty of each specific part (in Project, in the code below). You can change it to a custom iProperty too by quoting/unquoting the appropriate lines. The code was found here : https://forums.autodesk.com/t5/inventor-customization/how-to-assign-structured-item-numbers-to-a-ipr...

 

Code :

 Sub Main()
        Dim oAssemblyDocument As AssemblyDocument
        oAssemblyDocument = ThisDoc.Document

        Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
        oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition

        Dim oBOM As BOM
        oBOM = oAssemblyComponentDefinition.BOM
        oBom.StructuredViewEnabled = True
        Dim oBOMView As BOMView
        oBOMView = oBom.BOMViews(2) 'Structured view
        oBom.StructuredViewFirstLevelOnly = False
        oBom.StructuredViewDelimiter = "."

        Call RecursiveCheckAndSetProps(oBOMView.BOMRows)

    End Sub

    Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator)

        For Each oBOMRow As BOMRow In oRowsElements
            Dim oComponentDefinition As ComponentDefinition
            oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)

            Dim oBOMItemNumber As String
            oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
            ' MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on
			
'			'if you want standard iproperty (e.g. "project")        
            Dim oComponentDefinitionPropertySet As PropertySet
            oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item(3) 'design tracking
            oComponentDefinitionPropertySet.ItemByPropId(7).Value = oBOMItemNumber  '7 is project property
			
'			'if you want custom iproperty then
'			Dim oComponentDefinitionPropertySet As PropertySet
'            oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
'            'custom property tab
' 			Try
'                'if already exists then set it 
'                oComponentDefinitionPropertySet.Item("ITEMNUM").Value = oBOMItemNumber
'            Catch ex As Exception
'                'else add it
'                oComponentDefinitionPropertySet.Add(oBOMItemNumber, "ITEMNUM")
'            End Try
'            'creates the custom property and inputs the value

            If Not oBOMRow.ChildRows Is Nothing Then
                Call RecursiveCheckAndSetProps(oBOMRow.ChildRows)
            End If
        Next
    End Sub

So in the Sketched Symbol, I'm pulling the "Project" value when attached to the view (with hidden leader). I'm also pullin the "Description" value to display the part name.

 

As for the View Scale, I found a VBA macro that show a message displaying a view number with it's scale, for all the inserted views. But I didn't find a way to store that information. My preliminary idea is to use the code to inject the scale value into the part/welded assy. iProperties. Also, the code needs conditional formatting for scales higher that 0 vs. lower that 0 ( scl = 0.5 -> 1: scl^-1, scl = 2 -> 2:1)

 

Code

    Dim oDoc As Document 
    oDoc = ThisApplication.ActiveDocument 
    
    If oDoc.DocumentType = kDrawingDocumentObject Then 
    
        Dim oDrgDoc As DrawingDocument 
        oDrgDoc = oDoc 
              
        Dim oSheets As Sheets 
        oSheets = oDrgDoc.Sheets 
        Dim oSheet As Sheet 
        
        For Each oSheet In oSheets 
            Dim oDrgViews As DrawingViews 
            oDrgViews = oSheet.DrawingViews 
            Dim oDrgView As DrawingView 
            Dim msg As String 
            Dim i As Integer 
            i = 1 
            For Each oDrgView In oDrgViews 
                Dim scl As Double 
                scl = oDrgView.Scale 

                msg = "View No: " & i & vbCr & _ 
                           "View Scale  : " & scl 
                i = i + 1
               MsgBox (msg) 
            Next 
        Next 
    End If

Sketch DefinitionSketch Definition

Sketch PreviewSketch Preview

I'm not an iLogic/VB pro, but will try to keep you posted if I find a way to store the scale values in some ways. Feel free to post your suggestions!

0 Likes