Can I change this working way of rule from point to coordinate

Can I change this working way of rule from point to coordinate

ssiem
Contributor Contributor
456 Views
10 Replies
Message 1 of 11

Can I change this working way of rule from point to coordinate

ssiem
Contributor
Contributor

Hi

I got rule to generate part list on drawing and It place part list corner of Title Block

problem is it make error often

so i want to change this rule to place by coordinate that i put coordinate like '(100,100)' in a code 

could you help me?

 Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Add PartsLists - iLogic")
	For Each oSheet As Inventor.Sheet In oSheets
		oSheet.Activate
		If oSheet.PartsLists.Count > 0 Then Continue For
		If oSheet.DrawingViews.Count = 0 Then Continue For
		If oSheet.TitleBlock Is Nothing Then Continue For
		Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
		Dim oTBPos As Point2d = oSheet.TitleBlock.RangeBox.MaxPoint
		Dim oInsPt As Point2d = oTG.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2)
		Dim oPList As PartsList = oSheet.PartsLists.Add(oView, oInsPt)
		oDDoc.Update
		Dim oPL_Corner As Point2d = oTG.CreatePoint2d(oPList.RangeBox.MaxPoint.X, oPList.RangeBox.MinPoint.Y)
		Dim oPLPos As Point2d = oPList.Position.Copy
		oPLPos.TranslateBy(oPL_Corner.VectorTo(oTBPos))
		oPList.Position = oPLPos
	Next
	oASheet.Activate
	oTrans.End
	oDDoc.Update2(True)
End Sub
0 Likes
457 Views
10 Replies
Replies (10)
Message 2 of 11

FINET_Laurent
Advisor
Advisor

Hi @ssiem,

 

You could use the folowing code : 

 Sub Main
	 
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
		
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Add PartsLists - iLogic")
	
	Dim userX As Double = InputBox("Part list X coordinate value (mm)", "Please define :", "") / 10
	Dim userY As Double = InputBox("Part list Y coordinate value (mm)", "Please define :", "") / 10
	
	For Each oSheet As Inventor.Sheet In oSheets
		oSheet.Activate
		
		If oSheet.PartsLists.Count > 0 Then Continue For
		If oSheet.DrawingViews.Count = 0 Then Continue For
		If oSheet.TitleBlock Is Nothing Then Continue For
			
		Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
		Dim oInsPt As Point2d = oTG.CreatePoint2d(userX, userY)
		Dim oPList As PartsList = oSheet.PartsLists.Add(oView, oInsPt)
		
		Dim pListWidth As Double = oPList.RangeBox.MaxPoint.X - oPList.RangeBox.MinPoint.X
		Dim pListHeight As Double = oPList.RangeBox.MaxPoint.Y - oPList.RangeBox.MinPoint.Y
		oPList.Position = oTG.CreatePoint2d(oPList.Position.X + (pListWidth / 2) , oPList.Position.Y + (pListHeight / 2))
		
		oDDoc.Update
	
	Next
	
	oASheet.Activate
	oTrans.End
	oDDoc.Update2(True)
	
End Sub

 

 

Note the insertion point here is the center of the part list (line 26 to 28). You can remove those to get the default insertion point (top right corner).

 

Kind regards,

FINET L.

 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 11

FINET_Laurent
Advisor
Advisor

@ssiem,

 

Also, do you know what is causing the error? It might not be related to the title block relative positionning.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 4 of 11

ssiem
Contributor
Contributor

thank you for helping me

i've run code just before and this error is happened

ssiem_0-1695819234867.png

this is line 24

 

		Dim oPList As PartsList = oSheet.PartsLists.Add(oView, oInsPt)

 actually i've tried with chatgpt to change rule

same error happen everytime when i try something

0 Likes
Message 5 of 11

WCrihfield
Mentor
Mentor

Hi @ssiem.  Do your sheets now include a true TitleBlock, not just geometry similar to a TitleBlock within the Border?  Is it maybe encountering a Part in the sheet's first DrawingView, instead of an Assembly?  Is it possible that the assembly's BOM does not have either the 'Structured' or the 'Parts Only' BOMView's enabled?

Also, below is link to your previous post related to this task, just for others to reference.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/can-i-put-partlist-on-same-position-... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 11

ssiem
Contributor
Contributor

amazing you correct 3 out of 3

but I modify title block puting text box for partnumber or etc, i put drawing of part not assembly for first sheet, i activated structured and part only and it fail again

and I've checked your reference and it's me

it looks my template is problem 

it runs well with inventor basic template

I attached my template could you help me?

0 Likes
Message 7 of 11

WCrihfield
Mentor
Mentor

OK.  I see now that there is a TitleBlock present on your sheet, but it is just an empty rectangle around where your Border geometry is for the TitleBlock related information.  I would suggest that you transfer just that geometry and text boxes from your Border that would normally be within a TitleBlock, to that TitleBlock, instead of keeping it all within your Border.  However, that is just my opinion, and if what you currently have is working OK for you, that's the main thing.  Since that outline is in place for the TitleBlock entity, that should work OK with what we are trying to do here with positioning your PartsList.  Not sure what additional problems these code processes may be encountering.

 

By the way, when you show an error message for us to review, it is best if you are looking at the second tab within that error message, because that usually includes more information that might be useful to us.  And it also may be best to type what it says here in English, because some of us (myself included) can not read the language within the image you posted above, and since it is an image, we can not select the text to attempt to translate it to our language.  I know that can be a pain though.  It would be nice if the contents of those error messages was selectable, so we could copy it to our clipboard.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 11

ssiem
Contributor
Contributor

Thanks for your feedback

I will follow your recommandation

and I apolocise my carelessness about language

I just followed your recommandation what take information from Border to Title block where it should be in

and I run code but same error is generated

ssiem_0-1695829467427.png

error message(original)

 

System.ArgumentException: 매개 변수가 틀립니다. (예외가 발생한 HRESULT: 0x80070057 (E_INVALIDARG))
위치: System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
위치: Inventor.PartsLists.Add(Object ViewOrModel, Point2d PlacementPoint, PartsListLevelEnum Level, Object NumberingScheme, Int32 NumberOfSections, Boolean WrapLeft)
위치: ThisRule.Main() 파일 문서 조립품1-1 내 규칙 규칙2:줄 16
위치: Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
위치: iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

error message(translated)

System.ArgumentException: parameter incorrect (HRESULT with exception: 0x80070057 (E_INVALIDARG))
Location: System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
위치: Inventor.PartsLists.Add(Object ViewOrModel, Point2d PlacementPoint, PartsListLevelEnum Level, Object NumberingScheme, Int32 NumberOfSections, Boolean WrapLeft)
Location: This Rule.Main() File Document Assembly 1-1 Rule 2: Line 16
Location: Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
Location: iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

and i use this code from last post

 Sub Main
   If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
   Dim oDDoc As DrawingDocument = ThisDoc.Document
   Dim oSheets As Inventor.Sheets = oDDoc.Sheets
   Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
   Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
   Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Add PartsLists - iLogic")
   For Each oSheet As Inventor.Sheet In oSheets
      oSheet.Activate
      If oSheet.PartsLists.Count > 0 Then Continue For
      If oSheet.DrawingViews.Count = 0 Then Continue For
      If oSheet.TitleBlock Is Nothing Then Continue For
      Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
      Dim oTBPos As Point2d = oSheet.TitleBlock.RangeBox.MaxPoint
      Dim oInsPt As Point2d = oTG.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2)
      Dim oPList As PartsList = oSheet.PartsLists.Add(oView, oInsPt)
      oDDoc.Update
      Dim oPL_Corner As Point2d = oTG.CreatePoint2d(oPList.RangeBox.MaxPoint.X, oPList.RangeBox.MinPoint.Y)
      Dim oPLPos As Point2d = oPList.Position.Copy
      oPLPos.TranslateBy(oPL_Corner.VectorTo(oTBPos))
      oPList.Position = oPLPos
   Next
   oASheet.Activate
   oTrans.End
   oDDoc.Update2(True)
End Sub

I attached modified template that I use on test

and below is first sheet picture 

it is first sheet and it looks first sheet is not activated but I think error cuz I'm doing remote desktop in office from my home

ssiem_1-1695829934998.png

 

did I something wrong again it's hard to understand proper Titleblock please help me

0 Likes
Message 9 of 11

WCrihfield
Mentor
Mentor

Hi @ssiem.  Thank you for posting the other error dialog image, and the translated contents of it.  I was also actually able to read some of the text in that view of the error message image also this time.  We can clearly see on the third line of text within the error message that it is encountering the error at the specific point where the PartsList.Add method is being called.  Since there are only two input parameters for that method, and it is saying that there is an invalid argument, and you have covered all the other possible causes of the problem, I now have another theory, but not necessarily a solution.  There may simply be something about that first view on that page that it does not like, for some reason.  We know that this method will fail if the sheet that you are trying to add the PartsList to is not the active sheet, but we are activating each sheet as we loop through them, so that does not seem like it could be the problem.  I am not sure if the type of DrawingView makes any difference, since that is not mentioned in the help documentation, but I wander if the view you specify must be a base view, or otherwise independent, rather than a projected, auxiliary, or section view, which tend to have 'parent' views.  I don't think this error has anything to do with the Point2d object we are providing to that method, so it must be related to the view.  I am about out of ideas.  I am not that familiar with interacting with a DWG type Inventor drawings, since all of ours have always been the IDW file type.  I doubt the file type of the drawing makes any difference though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 11

ssiem
Contributor
Contributor

I think i figure out

the problem is language

simillar problem was happened before

there is parameter or function has different name

last time it was a 'structured' and it not work in my korean language pack

it work by '구조'

i have english language inventor and korean language inventor

and i test with same test dummy file with different language

english version work well but korean version not

the problem is i can't find what word should be korean

could you help me please?

0 Likes
Message 11 of 11

WCrihfield
Mentor
Mentor

Hi @ssiem.  I am not sure I would be able to help with determining which alternate words to use while writing code for another language version of Inventor.  When I need to translate text I see in a forum post from a language I am not fluent in, I usually just copy the text to the clipboard, then paste it at https://www.bing.com/Translator website, which will guess which language that is, then I choose my own language in the other side to see the same text in my language.  I do know that there are several tactics that can be used in some places to help make codes more universal (work for most languages).  For instance, some things have a DisplayName property, and maybe a regular Name property, but some things also have an InternalName property which can be used, that does not change between languages.  And most Enums have both a 'readable' value, and a numerical value, and in those cases, you can use the numerical values, even though they are more difficult to read later, unless you include comments.  You may need to contact someone at Autodesk directly about those types of questions.  Or maybe a local company that supplies Autodesk software and related services to local businesses.  Those types of places often provide technical support and training, if your company has purchased your software or a subscription from them.

 

When specifying which level of the BOM to use when adding a PartsList to drawing sheet, we can use the PartsListLevelEnum, which has 4 possible values.  You can specify the numerical value of the variation you wan to use there.  And when trying to specify which view (BOMView) of the BOM you want to work with, there is a similar method there too.  You could simply try to use the BOM.BOMViews.Item() property, but then you would have to specify a String or an Integer.  The String would likely be language specific, and the Integer can be unstable, depending on which views are enabled or not.  So, instead you can iterate each BOMView In BOM.BOMViews, and check each one with BOMView.ViewType, which has a value from the BOMViewTypeEnum.  Another opportunity to use a numerical value while checking which one you have, before proceeding.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes