Change between different JPG's in title block (using iLogic)

Change between different JPG's in title block (using iLogic)

Anonymous
Not applicable
1,492 Views
13 Replies
Message 1 of 14

Change between different JPG's in title block (using iLogic)

Anonymous
Not applicable

Hello,

 

I am making a title block in which 4 logos (File format JPG) have to be processed. The user can then choose via a form which JPG should be visible on the title block.
Now I have already googled for a possible starting point or a possibility to write this in a code, but unfortunately I have not been able to find anything yet. Nor do I believe that this would not be possible. The current situation is that the IDW file contains 4 title blocks, each with the relevant JPG file. But if the user needs to switch logos (JPG), they must write down the data entered for the relevant title block. Then delete the title block and insert the new title block and re-enter the data. This is time consuming and a title block in which I would only change the logo (JPG) would save a lot of time. so hopefully someone has a possible solution or knows how to start this code.

 

Regards, Joop

0 Likes
1,493 Views
13 Replies
Replies (13)
Message 2 of 14

JoãoASilva
Advocate
Advocate

@Anonymous 

 

I've got you covered:

https://knowledge.autodesk.com/community/screencast/62d50fd9-e36c-4f7e-b441-13bc3f8dce55

 

You can find 3 rules attached. Change them as you see fit.

 

If you want to make the form exactly the same:

JoãoASilva_0-1615378944260.png JoãoASilva_1-1615378968678.png

 

 

João Silva

Mechanical Engineer

 

Message 3 of 14

Anonymous
Not applicable

@JoãoASilva 

thank you for your response to the question I posted on this forum.
I have looked at the link and also the code and it is very interesting. But the Title block I'm working on is pretty much done. I have processed the changes of manufacturer in a "Case" method. But I would like to load / place the logos (jpg) of the relevant supplier in the title block if it is selected.
Because the original idw that we worked with had 4 title blocks, 1 title block for each supplier. I have now merged these into 1 title block. And I have this working :-).
But as mentioned above, I only run into the jpgs
Hopefully you have an idea how I can visibly / load this code using this code.

Regards, Joop

0 Likes
Message 4 of 14

JoãoASilva
Advocate
Advocate

@Anonymous ,

 

You can finish your Title Block, and then make various copies of it (Right Click > Copy), just changing the logo on each one.

Then, just change the Title Block Name to reflect the .jpg file in it.

Using the code, you can call the Title Block to be placed. You can always add more, or change the current existing, without having to rewrite the code.

 

I assume you are creating a template .idw, with a fully edited Title Block by you.

You want:

  • 1 Title Block;
  • 1 form calling rules;
  • 4 rules that will "inject" a .jpeg in the Title Block;

I'm suggesting:

  • 4 Title Blocks;
  • 1 form calling rules;
  • 1 rule to call the correspondent .jpeg Title Block;

If you do as I'm suggesting, you can manually adjust the .jpeg files as you desire.

Having a code do that for you, is much more complicated.

 

Either way, you will click a button in a form that will place the .jpeg in the Title Block.

 

Correct me if i'm not understanding what you are trying to achieve.

João Silva

Mechanical Engineer

 

0 Likes
Message 5 of 14

WCrihfield
Mentor
Mentor

This is a quickie code, but does the job for me in my tests.  It looks in the 'active' sheet of the 'active' drawing for the first SketchImage, captures its 'position', deletes it, then adds another image at that same position.

I suppose you could do more to control the size and orientation of the other image, but if both images are the same type, size, orientation, resolution, etc, it most likely wouldn't cause any problems.  You could also use the SketchImage's 'BoundaryGeometry' to help control it.

Anyways, here's the iLogic code:

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oTBDef As TitleBlockDefinition = oSheet.TitleBlock.Definition
Dim oSketch As DrawingSketch
oTBDef.Edit(oSketch)
Dim oImg As SketchImage = oSketch.SketchImages.Item(1)
Dim oPos As Point2d = oImg.Position
oImg.Delete
oSketch.SketchImages.Add("C:\Temp\Replacement Image.png", oPos, True)
oTBDef.ExitEdit(True)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 14

Anonymous
Not applicable
@JoãoASilva

I read your comment and thought about this overnight.
You have indeed read well how I would like to make it, but I thought about it overnight and came to the conclusion that what you propose to do. And I will have to adjust my plan. I personally think that my early knowledge of iLogic is also the smartest option for me without breaking my head about this. I have previously programmed in Vb.net but this is slightly different from iLogic, but I do see the similarities but also where it is limited. an example is that you can create a beautifully personalized form at VB.net while it is quite basic in Inventor. From this comes the question whether it is possible to create a Form in VB.net and link it to the iLogic rules?
So now I'm going to make 4 copies of the title block and give it the correct name. Then I will see if I can start making the code.

Regards, Joop
0 Likes
Message 7 of 14

Anonymous
Not applicable
Thank you comment and code.
I have read your comment and am still trying to understand it and how I can apply it to my idw file. but I will try to send the idw file with your code.

Regards, Joop
0 Likes
Message 8 of 14

WCrihfield
Mentor
Mentor

If you're used to coding in vb.net, that's great, because iLogic uses vb.net.  In Inventor, iLogic is an add-in that includes a lot of special Interfaces, Types (Classes), Methods, and couple UI access utilities, that are custom to Inventor to make it easier for us to use for interacting with Inventor.

You can do way more with an iLogic rule than most would guess, because of being able to use all of the vb.net's already established capabilities.

For instance, since you mentioned Forms, I have created several iLogic rules that create their own Windows Form right in the same rule that is going to be using and reacting to the form.  Here is a link to one of my earlier contribution posts, where I demonstrate this in an example.  I know it's not as 'user friendly' to create them entirely by code, but it is an option.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 14

Stakin
Collaborator
Collaborator

Please prepare four pic at the "C:\Temp" Named:image1.jpg\Image2.jpg...Image4.jpg

run below code

 

 

Public Sub Main()
    Dim oimageNum As String
    oimageNum=InputBox(" Picture Serial Number:","Please Input The serial number of the picture",1)

    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    Dim oTitleBlockDef As TitleBlockDefinition
    Dim oNImage As  SketchImage
    If oDrawDoc.TitleBlockDefinitions.Item("Sample Title Block") is Nothing then
    Call CreateTitleBlockDefinition()
    end if

    oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item("Sample Title Block")
    For Each oNImage In oTitleBlockDef.Sketch.SketchImages
    	oNImage.Visible=0
    Next
    oTitleBlockDef.Sketch.SketchImages.Item(Val(oimageNum)).Visible=1

    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet


    If Not oSheet.TitleBlock Is Nothing Then
        oSheet.TitleBlock.Delete
    End If

  
    Dim sPromptStrings(1 To 2) As String
    sPromptStrings(1) = "String 1"
    sPromptStrings(2) = "String 2"

    Dim oTitleBlock As TitleBlock
    oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef, , sPromptStrings)


End Sub


Public Sub CreateTitleBlockDefinition()

    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    Dim oTitleBlockDef As TitleBlockDefinition
    oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Add("Sample Title Block")


    Dim oSketch As DrawingSketch
    Call oTitleBlockDef.Edit(oSketch)

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Call oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(9, 3))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 1.5), oTG.CreatePoint2d(9, 1.5))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 2.25), oTG.CreatePoint2d(9, 2.25))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(4.5, 1.5), oTG.CreatePoint2d(4.5, 2.25))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(3, 2.25), oTG.CreatePoint2d(3, 3))
    Call oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(6, 2.25), oTG.CreatePoint2d(6, 3))


    Dim sText As String
    sText = "TITLE BLOCK"
    Dim oTextBox As TextBox
    oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(4.5, 0.75), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

    sText = "Static Text"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(0, 1.5), oTG.CreatePoint2d(4.5, 2.25), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

    sText = "<Prompt>Enter text 1</Prompt>"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(4.5, 1.5), oTG.CreatePoint2d(9, 2.25), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

     sText = "<Prompt>Enter text 2</Prompt>"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(0, 2.25), oTG.CreatePoint2d(3, 3), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

    sText = "<Property Document='drawing' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='4' />"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(3, 2.25), oTG.CreatePoint2d(6, 3), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter

  
    sText = "<Property Document='drawing' FormatID='{F29F85E0-4FF9-1068-AB91-08002B27B3D9}' PropertyID='3' />"
    oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(6, 2.25), oTG.CreatePoint2d(9, 3), sText)
    oTextBox.VerticalJustification = kAlignTextMiddle
    oTextBox.HorizontalJustification = kAlignTextCenter
    Dim oPos As Point2d
    oPos=oTG.CreatePoint2d(8, 4)
    Dim oImg As SketchImage 
    Img= oSketch.SketchImages.Add("C:\Temp\Image1.jpg", oPos, True")
    Call Img.Visible=0
    Img= oSketch.SketchImages.Add("C:\Temp\Image2.jpg", oPos, True")
    Call Img.Visible=0
    Img= oSketch.SketchImages.Add("C:\Temp\Image3.jpg", oPos, True")
    Call Img.Visible=0
    Img= oSketch.SketchImages.Add("C:\Temp\Image4.jpg", oPos, True")
    Call Img.Visible=0

    Call oTitleBlockDef.ExitEdit(True)
End Sub

 

Message 10 of 14

Anonymous
Not applicable

@JoãoASilva 

I tested the code and it worked with the title block with ipropertties.custom - texten.

But in these tests I found out that the iproperties.custom texts are also displayed on all other sheets. So "subject" of sheet 1 is also displayed on sheet 2 etc.

So this is not good, because sheet 2 has a different subject than sheet 1.

So I converted all sheet-dependent text / label to Prompted Entry's.

Now I've done kdit and then started testing again and then error messages pop up.
How can I fix this so that it works properly again?

 

Thank you in advance for the help.

 

Regards, Joop

0 Likes
Message 11 of 14

JoãoASilva
Advocate
Advocate

@Anonymous ,

 


@Anonymous wrote:

But in these tests I found out that the iproperties.custom texts are also displayed on all other sheets. So "subject" of sheet 1 is also displayed on sheet 2 etc.

So this is not good, because sheet 2 has a different subject than sheet 1.


What exactly do you mean by "subject"?

You can edit the Title Block to show only what you want:

JoãoASilva_0-1617109027685.png

^In this case, you would edit what you want to show when you have Title Block 1 active. Then you do the same for all the other cases.

 


@Anonymous wrote:

So I converted all sheet-dependent text / label to Prompted Entry's.

Now I've done kdit and then started testing again and then error messages pop up.
How can I fix this so that it works properly again?


You don't need to create entry's for something that Inventor will fetch from the model iProperties.

 

The best way to help you, would be if you could share the error message that pops up, as well as the drawing file you are using.

João Silva

Mechanical Engineer

 

0 Likes
Message 12 of 14

JoãoASilva
Advocate
Advocate

@Anonymous ,

I won't share the file you sent me, but leave here part of a solution, so others can use in the future.

The error you got was normal, since the Title Block couldn’t be placed because of the prompted entries on it.

 

I've got 2 workaround's.

  1. Input Box for every entry before placing the Title Block;
  2. Leave all prompted entries blank and fill them later;

1.

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock

Try
	oTitleBlock.Delete
Catch
End Try

'Create as many as you need
Dim oGetekend As String = InputBox("Getenked:", "Prompted Entries:")
Dim oDatum As String = InputBox("Datum:", "Prompted Entries:")
Dim oWijzigingletter As String = InputBox("Wijzigingletter:", "Prompted Entries:")
Dim oAantal As String = InputBox("Aantal:", "Prompted Entries:")

Try
	'Change name between quotes to match your title block name
	ActiveSheet.SetTitleBlock("Test_stempel", oGetekend, oDatum, oWijzigingletter, oAantal)
Catch
	'Change name between single quotes to match your title block name
	MsgBox("No 'Test_stempel' found in this drawing!", , "Warning:")
End Try

 

2.

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock

Try
	oTitleBlock.Delete
Catch
End Try

Try
	'Change name between quotes to match your title block name
	'Leave <""> as many as the number of entries you have
	ActiveSheet.SetTitleBlock("Test_stempel", "","","","")
Catch
	'Change name between single quotes to match your title block name
	MsgBox("No 'Test_stempel' found in this drawing!", , "Warning:")
End Try

You can fill them later here:

JoãoASilva_0-1617203069735.png

JoãoASilva_1-1617203109278.png

 

 

I didn't had much time to work around on this.

Try it and give some feedback!

João Silva

Mechanical Engineer

 

0 Likes
Message 13 of 14

Anonymous
Not applicable

for the challenge with inserting the title block (provided with prompted entries) I devised the step-by-step plan below.
step 1: define memory locations (dim x as string)
step 2: read values from prompted entries in title block
step 3: delete title block
step 4: insert new title block
step 5: write values in prompted entries

could this work if i made this in iLogic?

Regards, Joop

0 Likes
Message 14 of 14

A.Acheson
Mentor
Mentor

@Anonymous 

 

What you propose is all possible with VB.Net and the API with some Ilogic. Here is a link to another post that deals with similar content. 

https://forums.autodesk.com/t5/inventor-customization/ilogic-move-title-block-to-top-right-or-other-corner/m-p/10226702#M123172

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes