cancel
Showing results for 
Search instead for 
Did you mean: 

duplicate class and its attributes

SOLVED
Highlighted
Occasional Contributor

duplicate class and its attributes

Hi,

 

I've written a macro in MEGA 2009 that made a copy of an existing class and its attributes. Now I want to use this in HOPEX V2R1.

 

Sub CmdInvoke (objMega, intCommandNumber)
		
		Dim aDuplicateObject
		Dim oPackage, iPackage
		Dim PackageId
		'Dim oDiagram
		Dim oAttr, iAttr
		Dim aDuplicateAttribute
		Dim NewName
    Dim ExpType

		oPackage = objMega.getcollection("OwnerPackage")
    if oPackage.count = 1 then
      for each iPackage in oPackage
        NewName = Create_New_Name(objMega.GetProp("Short Name"), iPackage)
        set aDuplicateObject = iPackage.Getcollection("OwnedClass").Create(NewName)
        aDuplicateObject.SetProp "SQLName", objMega.GetProp("SQLName")
        aDuplicateObject.SetProp "Comment", objMega.GetProp("Comment")

        aDuplicateObject.GetCollection("OwnerPackage").Add(iPackage)

        'Attributes
				oAttr = objMega.GetCollection("Attribute")
				for each iAttr in oAttr
					set aDuplicateAttribute = aDuplicateObject.GetCollection("Attribute").Add(iAttr.GetProp("Local Name"))

					aDuplicateAttribute.SetProp "Length", iAttr.GetProp("Length")
					aDuplicateAttribute.SetProp "Decimal", iAttr.GetProp("Decimal")
					aDuplicateAttribute.SetProp "SQLName", iAttr.GetProp("SQLName")
					aDuplicateAttribute.SetProp "DEX Enumeration", iAttr.GetProp("DEX Enumeration")
					aDuplicateAttribute.SetProp "Comment", iAttr.GetProp("Comment")
					aDuplicateAttribute.SetProp "Order", iAttr.GetProp("Order")
	        'ExpressionType
          ExpType= iAttr.getCollection("TypeClass")
					if exptype.count = 1 then
	    	    aDuplicateAttribute.GetCollection("TypeClass").Add(ExpType.Item(1))
					end if
				next
      next
    else
      msgbox "niks gevonden"
    end if
End Sub

function Create_New_Name(ClassName, iPackage)

	dim oClass
	dim ClaSuffixCount
  dim strCount
  Dim RetVal
	Dim DQ

	DQ = """"

	BoolNameOk = false

  for ClaSuffixCount = 1 to 9
    if len(ClaSuffixCount) = 1 then
      strCount = "0" & CStr(ClaSuffixCount)
		else
			strCount = CStr(ClaSuffixCount)
    end if

    oClass = iPackage.GetSelection("Select Class where [short name] = " & dq & ClassName & "_" & strCount & dq)
      if oClass.Count = 0 then
        RetVal = ClassName & "_" & strCount
        exit for
      end if
	next
  Create_New_Name = RetVal
end function

This actually works fine, but for 1 thing. The name of the attributes of the class is not correctly set:

 

Instead of the name (like ID or Aliasname) I get the value "(Uninitialized)"

Capture.PNG

Anyone any idea what I should change in my code so the name is copied?

tnx.

2 REPLIES
MEGA

Re: duplicate class and its attributes

Hello

 

This may not be related to the script.

Try to create the same data in interactive mode.

 

There is a known issues about Attribute (DM) in Entity (DM)

See KB https://community.mega.com/t5/custom/page/page-id/mega-kb-solution?sid=50157000001H7QTAA0

 

Jerome
Occasional Contributor

Re: duplicate class and its attributes

Hi Jerome,

thank you for the response. We will discuss the proposed solution.

But given your answer that the name is changed to '(unitialised)' when the data type is changed, i've also tested another workaround:

'ExpressionType
          ExpType= iAttr.getCollection("TypeClass")
					if exptype.count = 1 then
	    	    aDuplicateAttribute.GetCollection("TypeClass").Add(ExpType.Item(1))
					end if

					aDuplicateAttribute.SetProp "Local Name", iAttr.GetProp("Local Name")'

 Reset the name after the attributes was connected to the TypeClass.

 

 

This also works. So we will see what's the best solution for now.

 

Kind regards,

 

Jeroen.