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: 

iLogic code to vary line spacing of titles in a title block

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
GORDONMABIYA
171 Views, 6 Replies

iLogic code to vary line spacing of titles in a title block

Titles in my drawing title block are populated as custom iProperties. These titles can vary between 6 to 4 lines but must still fit in the same space.  The way to achieve this is to vary line spacing depending on the number of titles entered in custom iProperties menu.

 

The fill the entire space for titles the following line spaces must be maintained. 

6 titles - 7 2/5mm line spacing required

5 titles - 9 1/4mm line spacing required

4 titles - 12 1/3mm line spacing required

 

The titles are separate fields and are therefore spaced by parameters as shown in pic (not multiline text). 

 

I am clueless when it comes to iLogic. I am hoping that you guys can confirm if it can be done and assist if you can. 

 

I attach screenshots and .idw.  

 

Thanks!

6 REPLIES 6
Message 2 of 7
Stakin
in reply to: GORDONMABIYA

you can make 3 types titleblocks,6 title lines,5title lines,4title lines?

what are you want ?

set the line spaceing  by ilogic by the valid title lines?

or

insert correct title block ?

Message 3 of 7
WCrihfield
in reply to: GORDONMABIYA

Hi @GORDONMABIYA.  I agree with @Stakin that this could be handled by simply having a different TitleBlockDefinition for each case, then simply switch to a different TitleBlock when needed.  However, if you really want to stick with a single TitleBlock that has room for 6 lines of text then, we would need to know when to switch between the different offsets.  So, do all 6 of those custom iProperties always exist in every drawing file, or are there sometimes none of them present in the file, or sometimes only 4 of them present in the file?  And if all 6 of those custom iProperties always exist in every drawing file, then do they all have default values (such as "TITLE 1", "TITLE 2"), or are the ones you do not intend to use left empty/blank.  We need to know these things, because we need to know when the iLogic rule should be ran, and how the iLogic rule can possibly know when to change the parameter(s) to which values.

 

I see that the first dimension at the top of that stack of textboxes is just referencing a standard ModelParameter named "d16", then the next dimension down is pointing to that same parameter.  However, the dimensions after that all reference the parameter of the dimension just above it, instead of all referencing the same Parameter as the first dimension.  You will want to create a UserParameter, with a meaningful name such as "TitleBlockTitleLinesSpacing", then put that equation "7 mm + 2 mm / 5 ul" into that UserParameter, then force that first dimension to reference that UserParameter.  Then force all the other dimensions in that stack to reference the same UserParameter.  Then, when you make an iLogic rule, you can just modify the value of that one UserParameter as required.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

I also agree with @Stakin and @WCrihfield.

But if you decide to modify your TitleBlock definition in each drawing, here is sample how to do it. 

I was wondering how it works with the parameters in drawing nowadays. But I recommend you to use different approach.

 

Sub Main()
    Dim drawing As DrawingDocument = ThisDoc.Document
    Dim titleBlock As TitleBlock = drawing.ActiveSheet.TitleBlock
    Dim defSketch As Sketch
    titleBlock.Definition.Edit(defSketch)
    defSketch.DeferUpdates = True

    Dim linesCount As Integer = GetLinesCount(drawing)
    Dim lineSpace As Double = GetLineSpace(linesCount)

    Dim lineSpaceParam As Parameter = GetParameterByName(defSketch, "d16") ' d16 = Parameter name in definition sketch
    lineSpaceParam.Value = lineSpace

    defSketch.DeferUpdates = False
    titleBlock.Definition.ExitEdit()
End Sub

Private Function GetLineSpace(linesCount As Integer) As Double

    Dim lineSpace As Double = 0.74
    Select Case linesCount
        Case 4
            lineSpace = 1.233 ' [cm] - 4 titles - 12 1/3mm line spacing required
        Case 5
            lineSpace = 0.925 ' [cm] - 5 titles - 9 1/4mm line spacing required
        Case 6
            lineSpace = 0.74 ' [cm] - 6 titles - 7 2/5mm line spacing required
            '
    End Select
    Return lineSpace
End Function

Private Function GetLinesCount(drawing As DrawingDocument) As Integer

    Dim linesCount As Integer = 0
    For i As Integer = 6 To 1 Step -1
        Dim userDefinedProperties As String = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
        Dim value = drawing.PropertySets(userDefinedProperties)(String.Format("0{0} TITLE LINE {1}", i + 3, i)).Value
        If Not String.IsNullOrEmpty(value) Then
            linesCount = i
            Exit For
        End If
    Next
    Return linesCount
End Function

Function GetParameterByName(defSketch As Sketch, paramName As String) As Parameter
    For Each dimConstraint As DimensionConstraint In defSketch.DimensionConstraints
        Dim param As Parameter = dimConstraint.Parameter
        If param.Name = paramName Then Return param
    Next
    Return Nothing
End Function

 

Message 5 of 7
WCrihfield
in reply to: Michael.Navara

Good point @Michael.Navara.  I temporarily forgot about the odd situation with Parameters for those types of things in drawings.  We would have to access them through the DimensionConstraints of the DrawingSketch, as you are doing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7
Stakin
in reply to: Michael.Navara

@WCrihfield @Michael.Navara In this case,One type of titleblock means only on type of drawingsheets in one drawingDocument.,the code should loop between different drawing files 。

Message 7 of 7
Stakin
in reply to: WCrihfield

If the DimensionConstraints of the DrawingSketch could use the Parameters of the DrawingDocument,that will be even better

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report