Read parameter in a assembly from drawing file through ilogic

Read parameter in a assembly from drawing file through ilogic

FrankHermens4Y53K
Contributor Contributor
581 Views
3 Replies
Message 1 of 4

Read parameter in a assembly from drawing file through ilogic

FrankHermens4Y53K
Contributor
Contributor

Hello,

 

I cant figure out how to get the value of a parameter in a assembly from the drawing. 

Currently I make a parameter and a list for this parameter. Then the user sets the value of this parameter with a InputlistBox. I got this from this post:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/add-parameter-to-drawing-file-throug...

 

So now i want to get the value somthing like this:

If Parameter("Parameter_name") = "Value" Then
End if

But you cant access the parameter from the drawing like this. 

 

And yes i know you can do this but i want to use the parameter in a private sub so i cant use this.

oName = InputListBox("Prompt", List, "Value", Title := "Title", ListName := "List")

if oName = "Value" then
End if

 

Thanks in advance,

Frank

0 Likes
Accepted solutions (1)
582 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @FrankHermens4Y53K.  I'm not sure I fully understand the situation, but here are a few lines of code which take advantage of a couple of iLogic's shortcut snippets, that you may be able to use.  Since the assembly is basically referenced by the drawing, these two iLogic snippets should be able to access them by specifying their file name (without path, but with file extension) as the first input variable.  The object Type of the oListOfValues will be iList, which is similar to the ArrayList object.

oModelDoc = ThisDrawing.ModelDocument
oMDocName = System.IO.Path.GetFileName(oModelDoc.FullFileName)
oCurrentValue = Parameter.Value(oMDocName, "Param_Name")
oListOfValues = MultiValue.List(oMDocName, "Param_Name")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

tmathieson
Advocate
Advocate

HI @WCrihfield ,  i am trying to do the same thing in a way.  i want to retrieve the  value of a parameter in my assembly and base my drawing scale on it.

 

i have create the drawing, added the view, but when i try to get the parameter i get the error attached "can't find file", even though it exists and  on the drawing.  the error occurs "oCurrentValue" line. the only thing i can think of, and not sure this should matter, is that the dwg has not been saved yet.  i am running a rule in my assembly that creates the drawing, add desired views to appropriate pages, add some dims, notes, etc, and want to adjust views  scales accordingly... i don't think not having the dwg saved yet would be an issue, but....

 

Dim oView1 As DrawingView
 oView1 = oSheetS01.DrawingViews.AddBaseView(oAssemblyDoc, oPoint, 0.01, kFRONTViewOrientation, kHiddenLineDrawingViewStyle, "PAGE-S01")
 oView1.Name = "PROFILE"
 view_assy = oAssemblyDoc.FullFileName
 Logger.Debug("span a.." & view_assy)
 oMDocName = System.IO.Path.GetFileName(oAssemblyDoc.FullFileName)
 oCurrentValue = Parameter.Value(oMDocName, "SPAN_A")
 Logger.Debug("span b.." & oCurrentValue)
  view_span = Parameter(view_assy & ".SPAN_A")
  Logger.Debug("span.." & CStr(view_span))

  thanks for looking and any insight provided!!

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @tmathieson.  Using that 'Parameter.Value(docName, paramName)' iLogic snippet can be fairly tricky at times.  There is no proper, public documentation about what is required, or how to format either the "docAndParamName" variable in the one version of it, nor the "componentOrDocName" variable in the other version of it.  Nor is there any proper documentation about the 'scope' of this snippet (where, or how far it can reach in different situations).  When working with an assembly ComponentOccurrence object, you can simply put the ComponentOccurrence.Name value (as seen in the model browser tree) in there as the first input, but when you are working with a 'referenced' document directly, it is more complicated.  It is definitely looking for the file's name, without its path, but whether or not it wants to see the file's extension included is questionable.  Sometimes it seems that using Document.DisplayName works there, but that is a Read/Write property, and it may, or may not include the file's extension, depending on some settings.  I thing it depends on whether or not your PC (Windows Explorer) is set to show file extensions or not, which sucks.  Plus, the 'scope' of that snippet seems to include any document that can be found within the ActiveDocument.AllReferencedDocuments collection.  However, if this is the first view of any model you have placed into your drawing, then you may have to update the drawing after placing that first view, for the document reference to take root, before calling code to reach into that referenced document to get parameter values from it...just a thought.  

  So, if you want to avoid the confusion and uncertainty, you could switch from using API code there, instead of trying to use an iLogic shortcut snippet there.  

oCurrentValue = oAssemblyDoc.ComponentDefinition.Parameters.Item("SPAN_A").Value

That's what I usually do, when I really need to count on it working the way I planned it to.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes