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 and derive

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
jletcher
5183 Views, 20 Replies

ilogic and derive

In the sample code is a sample ilogic Derived parts and assembly but if you read the sample it is for molding and subtracting this from that..

 

Not being the expert at ilogic I really cant make heads or tails of what to steal to make what I need.

 

I have lets call it a side body and it will be the left. when the user inserts this into an assembly a form will pop up so he can configure the side body. What I would like to add is a yes or no to create the right as a derived part.

 

I can create the yes and no option but I don't know where to begin to make the code to derive the part.

 

The location to put the derived part would be the local workspace but would need a way to name the file as well.

 

Any help would be great.. A book would be better. Or better sambles or snippits..

20 REPLIES 20
Message 2 of 21
jletcher
in reply to: jletcher

Anyone?

Message 3 of 21

Hi jletcher,

Would it work to create the derived part in advance (not using iLogic) and have the iLogic Yes/No message simply replace the left side with the right side, etc. ?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Message 4 of 21

No not really. It is not a matter of replacing in an assembly what they are doing is creating the left side body and when they generate the part I need the oppisite hand to be made. The sample in help is really no help at all and there really is no help for ilogic.

 

If you ask me they should have made lots of sampl codes and a better help for ilogic it is a very good tool but if Autodesk is not going to provide help for this it is not a very friendly tool. I have been working on this all day and still can't make heads or tales of it.

 

I did get it to start a new part and thats it every time I try any code to derive it fails and fails.

 

Really want to learn this but I am getting frustrated at the lack of Autodesk to step up and make a book or better help and better code samples I am about to just forget about it.

 

I guess they just don't care anymore I remember when I was a tech for them they was so proud of the help that was in Inventor and at that time new users loved the help. Now not so help really sucks hell I can't even get my help to come up I have to go find it in the directory to start it.

 

I don't know I'm just about to give up on Inventor. I have one more client to help out then I will look and think do I really want to stay with Inventor because I don't like the way they are headed. They no longer care about the user just the stock holders.

Message 5 of 21

View of my form everything works great just have to figure this out. I have 80% of their parts done and they love it they don't have to do any models unless it is a custom conveyor.

 

yep can.JPG

Message 6 of 21

Hi jletcher,

 

I'll see what I can come up with, but as a rule I typically don't respond to posts that contain rants and hints of unconstrained frustration.

 

This is simply because I've tried to help frustrated people in the past and they end up becoming unpleasant toward the people trying to help. There is also a tendency for people to get distracted by their frustration, rather than concentrating on the question they're asking and providing clear details and examples, which of course makes it difficult and time consuming to help them.

 

So generally speaking I'll pass on posts that lack detail and contain rants and complaining, but I might have a need for something similar to the derived example in the near future, so I'll take some time to explore it.

 

I can't promise anything, but I'll post back if I have some luck.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

 

Message 7 of 21

Well don't worry about me getting frustrated with you or anyone that helps me. My frustrations are at Autodesk.

 

As far as explaining what I need I will do my best to make it clear.

 

My frustration never stop me it pushes me to find the answer and when I can't find it I look harder.

 

As far as rants yeah I am guilty of that for sure but I tried the nice way and it never got me anywhere just like my rants but it does make me feel better getting it of my chest.

 

But really have to step back and look at Autodesk and the direction they are going when I was a tech for them the end user is what we was tought was the most important thing and right now I just don't see it from them....

 

Thanks for anything you can help me with I will be working on this more tonight so if I get anywhere with it I will post.

 

And I will apologize for my rants I am man enough to do that...

 

I just would like to have the tools to learn ilogic....

Message 8 of 21

Hi jletcher,

 

Here is a quick example I came up with. It looks for a pre-selected part from within the assembly, and then creates a new derived file from that file and mirrors it. Then it places an instance of the derived part into the assembly and then finally it  replaces the selected file with the new derived one too.

 

You'll likely discard all of the file selection code and just hardcode in the file you're configuring, etc.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

'set a reference to the assembly component definintion.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition    

'get currently selected component
Dim oOccurrence as ComponentOccurrence
Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

Dim doc As Document
Dim CurFileName As String
Dim NewFileName As String

'set the selected item
oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1)

'get the selected item document occurrence name
doc = oOccurrence.Definition.Document

'get the path and file name of the selected item
CurFileName = doc.FullFileName

oQuestion = MessageBox.Show("Do you want to derive " & doc.DisplayName & " ?", "iLogic",MessageBoxButtons.YesNo)
If oQuestion = vbNo Then
Return
Else
' Initialize the string that defines the directory where the files will be created.
Dim sFilePath As String
sFilePath = "C:\Temp\"

' Create a new part file to derive the selected part into
'note: kPartDocumentObject is the default template
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

'Create a derived definition for the selected part
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(CurFileName)

' set the scale to use.
oDerivedPartDef.ScaleFactor = 1

'define the mirror plane
'kDerivedPartMirrorPlaneXY = 27393
'kDerivedPartMirrorPlaneYZ = 27394
'kDerivedPartMirrorPlaneXZ = 27395
oDerivedPartDef.MirrorPlane = 27393

' Create the derived part.
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)

'get a file name for the derived part
NewFileName = InputBox("Enter a name for the derived part file: ", "iLogic", doc.DisplayName & "_derived")

' Save and close the derived part.
oPartDoc.SaveAs(sFilePath & NewFileName & ".ipt", False)
oPartDoc.Close

'set a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create a  placement matrix
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix  
'set the matrix coordinates
oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

' Add a new occurrence of the derived part to the assembly
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add(sFilePath & NewFileName & ".ipt", oMatrix)

‘Replace the originally selected part with the derived part
'note: True = Replace All
oOccurrence.Replace (sFilePath & NewFileName & ".ipt", False)

End If

 

Message 9 of 21

Wow you must have done this a few times lol.

 

I really thank you for helping. Can you answer a few nore questions?

 

As I mention in an early post I will not be in an assembly but a part that really has not been made yet. Here are the steps I am trying to do.

 

I will have a directory with Master files this one is call side body.ipt..

 

Steps user will take.

 

1. user will select master file in this case side body.ipt (Work in progress)

2. Form will start as soon as part opens. (Done works)

3. user will configure part. (Flange, height, holes ect.) (Done works)

 

(Now this is where I am stuck and hard for me to explain but I will do my best. I have the yes or no for mirror in my form as you can see, but if yes is selected it wants to do it then but it can't because I have not generated the part yet the part I want mirrored will not be generated untill the user hits generate part.

 

So do I need to have another rule to do the mirror part after they hit generate part an input box or message box will pop up after and ask if I would like to make a mirror part from the generated part? Or is there a way to keep it in the form I have now and tell it to make the mirror part after generate is pressed?)

 

4. user will press generate and it will prompt the user to give the part a number. ( at this time if yes is sected in the form a mirror part will also be made (if it can work this way) and the part number of the mirror part will be one higher number. lets say main body (left side) part number 89563 miror part number 89564.)

 

5. user will hit done and close the master side body file.

6. user starts new assembly and inserts left side body, crossmembers, right side body.

 

I hope this clears things up a little.

 

And as I type there may be another way instead of mirror.

 

What if I have two configuraters one left one right. Both have same configurater form (no mirror option) but in the right have an option to link parameters with the left? Can this be done with ilogic? I was thinking that sometimes the flange length on oppisite hand may be smaller. and the height can be smaller. so maybe just have parameters that locate the holes so if I move the hole on the left the hole on the right will update?

 

What are your thoughts on this?

 

And again many many thanks for helping. 

Message 10 of 21

Hi jletcher,

 

Those details help a lot.

 

If I understand correctly, then I don't think a derived part is needed.

 

The approach I would take is to create a mirror feature to mirror the entire part wihin the part file (use the Mirror a Solid button with the Remove Original option). Then in your iLogic configurator you'll simply suppress or enable this mirror feature.

 

Or you could even have the code delete the mirror feature.

 

Or you could take the opposite approach and have the ilogic create mirror feature using the API tools, but that wouldn't be my preference.

 

Attached is a simple example file.

 

Edit:

It just occured to me that if these parts are to be generated by iLogic, but maintained by traditional modeling tools, then the derived link would be the better way to go. If that's the case I can have another look at deriving from the part file.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 11 of 21

Yes I thought of this as well the issue would be no link between the the left part to the right part.

 

95% of the time they will be the same left and right. Only 5% the left would not match the right.

 

So by doing it in this manner (it is easy) users will always have to remeber to change both.

 

(Trust me if you was here you would understand why this option would not be the best for this client. They have a hard time remembering what desk to sit at. They are not engineers. They are assembliers that have been brought in the office for good reasons they all have been here for 20 to 30 years and can't assemble because of age and the owner moved them in the office till they retire. You don't find that in any company. But makes it harder for me to make it lazy proof )

 

So I think a derived part is needed or a way to link the paramters so they don't have to change both.

 

Now you and I would make the one start a new file derive from the base  save it and move on. But I can't get them to remember how to add a sheet to a drawing after 3 weeks... I don't think they would understand or remember how to make a derived part.

 

You said:

It just occured to me that if these parts are to be generated by iLogic, but maintained by traditional modeling tools,

 

Yes and no, When I generate the left part it is a saveas file so the form goes with it so if they need to move a hole they will start the form make the change and hit done. By pressing done they will not generate a new part that will only happen if they press generate part. That is why I put that code to run alone.

 

So the left part after it is generated from the master file will be maintained by the form, the right would be derived so it will change after they hit update.

 

 

I hope this does not confuse you.

 

If you want to send me a message with your email I will email you my part so you can see how it works just don't want to post it for many reasons..

 

Many thanks again...

 

 

 

Message 12 of 21
jletcher
in reply to: jletcher

P.S.

 

 just don't laugh at the caveman ilogic code. Just learning it....

Message 13 of 21

Hi jletcher,

 

Okay here is an example that creates a mirrored, derived part of the original and saves it in the same directory as the original. The file name is generated without user input.

 

Edit: I fixed a slight bug.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

doc = ThisDoc.Document
path_and_name = ThisDoc.PathAndFileName(False) ' without extension

oQuestion = MessageBox.Show("Do you want to derive this file?", "iLogic",MessageBoxButtons.YesNo)
If oQuestion = vbNo Then
Return
Else

' Create a new part file to derive the selected part into
'note: kPartDocumentObject is the default template
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

'Create a derived definition for the selected part
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(ThisDoc.PathAndFileName(True) )

' set the scale to use
oDerivedPartDef.ScaleFactor = 1

'define the mirror plane
'kDerivedPartMirrorPlaneXY = 27393
'kDerivedPartMirrorPlaneYZ = 27394
'kDerivedPartMirrorPlaneXZ = 27395
oDerivedPartDef.MirrorPlane = 27394

' Create the derived part.
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)

' Save the new derived part.
oPartDoc.SaveAs(path_and_name & "_derived.ipt", False)
oPartDoc.Close
MessageBox.Show("New file created at:" & vblf & path_and_name & "_derived.ipt", "iLogic")

End If
Message 14 of 21

WOW you are good at this. I never knew it but I go to your blog every day just to feed your fish lol.

 

That works just like I would have wanted it to... perfect you are the man..

 

If you ever head to orlando florida look me up I owe you a dinner and tickets to Disney..

 

 

Message 15 of 21
Message 16 of 21
Anonymous
in reply to: Curtis_Waguespack

Hi Curtis 🙂

 

i try your rule of your site, work great but it's possible a same rule in assembly who replace in all part ???

 

Thanks for your help!

Message 17 of 21
Curtis_Waguespack
in reply to: Anonymous

Hi sergelachance,

 

Sorry, but I don't understand what you're asking. Can you explain what you have set up and what you're attempting to do?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 18 of 21
Anonymous
in reply to: jletcher

Sorry for my english 😞

 

Ok i try,  i want to replace the derived part in each part of my assembly, I have a master sketch who is derived on each part of my assembly. I trying with ilogic design copy but a huge bug, rename and replace all part and rule  in appearance but when i make a iproperties in my part the part number is the old :(. My manager dont want to use the vault :(,, i hope you understand with my horrible enslish

 

Thanks again Curtis, your are really important for all ilogic user 🙂

Message 19 of 21
Anonymous
in reply to: Curtis_Waguespack

That is my test, i put this rule in my assembly, to created and send to part the new path for derrived part

 

'present a File Selection dialog
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
EMPLACEMENT = oFileDlg.FileName
End If

MessageBox.Show("YOUR SKETCH FILE IS: " & EMPLACEMENT , "iLogic")
iProperties.Value("Custom", "EMPLACEMENT") = EMPLACEMENT


FOLDER = ThisDoc.Path
POSITION1 = InStrRev(FOLDER, "\")
POSITION2 = Right(FOLDER, Len(FOLDER) - POSITION1)


SKETCHNAME = POSITION2 & "_SKETCH" & ThisDoc.FileName & ":1"
iProperties.Value("Custom", "SKETCHNAME")=SKETCHNAME


'SEND TO PART, EMPLACEMENT IS PATH 🙂
Parameter(POSITION2 & "_FOND" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_DIV" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_DOS" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TAB" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TRTAB" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TABCOCHER" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TRTOP" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TOP" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_PORTE1" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_PORTE2" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_FILG" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_FILD" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_PANAPP" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TR1BASE" & ThisDoc.FileName & ":1","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
Parameter(POSITION2 & "_TR2BASE" & ThisDoc.FileName & ":2","EMPLACEMENT") = iProperties.Value("Custom", "EMPLACEMENT")
RuleParametersOutput()
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
ThisDoc.Save

 

and iin each part of this assembly i put a even triggers, iproperties change and a custom properties  "Folder" of a rule who replace the derrived part to my new path

 

i try that but dont work?

 

Dim oDoc as Document

oDoc = ThisDoc.Document

Dim oRefFile As FileDescriptor

Dim oOrigRefName As Object


'Replace the reference
oRefFile.ReplaceReference (selectedfile)
InventorVb.DocumentUpdate()
oOrigRefName = "FOLDER"

iLogicVb.UpdateWhenDone = True

 

Thanks for your help 🙂

 

 

 

 

 

Message 20 of 21
Anonymous
in reply to: Anonymous

ok i find now 🙂

 

 doc = ThisDoc.Document
 Dim oFD As FileDescriptor
 oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
 oFD.ReplaceReference(EMPLACEMENT)
 doc.Update()

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

Post to forums  

Autodesk Design & Make Report